PageRenderTime 25ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/www/source/login.php

http://firmkernel.googlecode.com/
PHP | 157 lines | 146 code | 1 blank | 10 comment | 1 complexity | b96813fb48a6584d78bd8f7dd360cdb5 MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. /*
  3. +-----------------------------------------------------------------------------+
  4. | $Id: login.php 2010-05-24 12:37:44Z Bleakwind $
  5. | Member Login
  6. | Copyright (c) 2003-2010 Bleakwind (www.weaverdream.com)
  7. | http://www.weaverdream.com/
  8. | Release under the GNU Lesser General Public License Version 3 (LGPLv3):
  9. | http://www.gnu.org/licenses/lgpl.html
  10. +-----------------------------------------------------------------------------+
  11. */
  12. if (!defined( 'ENTRY_INDEX')){
  13. echo "<h1>Forbidden</h1><p>You don't have permission to access on this server.</p>";
  14. exit;
  15. }
  16. // Member login
  17. function login_member($value, $submit)
  18. {
  19. global $SETTING,$LANGUAGE,$CONFIG,$CONFIGURE,$SESSION,$PROMPT,$db,$sys,$c,$ac;
  20. $ajax_response = new xajaxResponse();
  21. //$ajax_response->alert(print_r($value, true)); $ajax_response->assign($submit,"disabled",false); return $ajax_response;
  22. $error = false;
  23. $mid = "";
  24. $musername = "";
  25. if ( empty($value['verifycode']) || (strtolower($value['verifycode']) != strtolower($SESSION->_['vc_login'])) ) {
  26. if (!$error) {
  27. $error = true;
  28. $prompt_message = "<span class=\"prompt_failed\">".$LANGUAGE['s']['login']['verifycode_error']."</span>";
  29. $ajax_response->script("xajax_switch_verifycode('vc_login_show','".$CONFIGURE['common']['control_index']."','vc_login');");
  30. }
  31. }
  32. if ( empty($value['password']) ) {
  33. if (!$error) {
  34. $error = true;
  35. $prompt_message = "<span class=\"prompt_failed\">".$LANGUAGE['s']['login']['password_empty']."</span>";
  36. }
  37. } elseif ( mb_strwidth($value['password'],"UTF-8") < 4 ||
  38. mb_strwidth($value['password'],"UTF-8") > 60 ||
  39. preg_match("/[\x01-\x2E]|[\\x2F]|[\x3A-\x40]|[\x5B-\x5E]|[\x60]|[\x7B-\x7F]/",$value['password']) ) {
  40. if (!$error) {
  41. $error = true;
  42. $prompt_message = "<span class=\"prompt_failed\">".$LANGUAGE['s']['login']['password_error']."</span>";
  43. }
  44. }
  45. $value['username'] = strtolower(trim($value['username']));
  46. if ( empty($value['username']) ) {
  47. if (!$error) {
  48. $error = true;
  49. $prompt_message = "<span class=\"prompt_failed\">".$LANGUAGE['s']['login']['username_empty']."</span>";
  50. }
  51. } elseif ( (mb_strwidth($value['username'],"UTF-8") < 4 ||
  52. mb_strwidth($value['username'],"UTF-8") > 60 ||
  53. preg_match("/[\x01-\x2E]|[\\x2F]|[\x3A-\x40]|[\x5B-\x5E]|[\x60]|[\x7B-\x7F]/",$value['username']))
  54. && !preg_match("/^[a-z0-9-_\.]+@([a-z0-9][a-z0-9-]*\.)+[a-z]{2,4}$/i",$value['username']) ) {
  55. if (!$error) {
  56. $error = true;
  57. $prompt_message = "<span class=\"prompt_failed\">".$LANGUAGE['s']['login']['username_error']."</span>";
  58. }
  59. }else{
  60. // check the password
  61. if (preg_match("/^[a-z0-9-_\.]+@([a-z0-9][a-z0-9-]*\.)+[a-z]{2,4}$/i",$value['username'])){
  62. $sql = "SELECT id, username, password FROM ".DB_TABLE_MEMBER." WHERE email='".$value['username']."'";
  63. } else {
  64. $sql = "SELECT id, username, password FROM ".DB_TABLE_MEMBER." WHERE username='".$value['username']."'";
  65. }
  66. $result = &$db->Execute($sql);
  67. if (!$result) {
  68. $ajax_response->alert($db->ErrorMsg());
  69. } else {
  70. if ($result->EOF) {
  71. if (!$error) {
  72. $error = true;
  73. $prompt_message = "<span class=\"prompt_failed\">".$LANGUAGE['s']['login']['username_not_exist']."</span>";
  74. }
  75. } elseif ( $result->fields['password'] != func::str_encrypt($value['password'],$CONFIGURE['sys']['encrypt_mix']) ) {
  76. if (!$error) {
  77. $error = true;
  78. $prompt_message = "<span class=\"prompt_failed\">".$LANGUAGE['s']['login']['password_wrong']."</span>";
  79. }
  80. } else {
  81. $mid = $result->fields['id'];
  82. $musername = $result->fields['username'];
  83. }
  84. }
  85. }
  86. if($error){
  87. $ajax_response->assign("prompt_message","innerHTML",$prompt_message);
  88. $ajax_response->assign($submit,"value",$LANGUAGE['s']['login']['login_submit']);
  89. $ajax_response->assign($submit,"disabled",false);
  90. }else{
  91. $ajax_response->assign("prompt_message","innerHTML","");
  92. // Front session
  93. if($value['lifetime'] == "1"){
  94. $c->set_lifetime("31536000");
  95. }
  96. if ($value['lifetime'] == "3600" ||
  97. $value['lifetime'] == "86400" ||
  98. $value['lifetime'] == "604800" ||
  99. $value['lifetime'] == "2592000" ||
  100. $value['lifetime'] == "31536000" ) {
  101. $c->set_lifetime($value['lifetime']);
  102. }
  103. $c->set_cookie(array(
  104. $CONFIGURE['sys']['cookie_prefix']."mid" => $mid,
  105. $CONFIGURE['sys']['cookie_prefix']."musername" => $musername,
  106. ));
  107. $c->set_session(array(
  108. "mid" => $mid,
  109. "musername" => $musername,
  110. ));
  111. if (!empty($PROMPT['prompt_returnurl'])){
  112. $returnurl_index = $PROMPT['prompt_returnurl'];
  113. } else {
  114. $returnurl_index = $CONFIGURE['common']['control_index'];
  115. }
  116. $ajax_response->redirect($returnurl_index);
  117. }
  118. return $ajax_response;
  119. }
  120. $bwajax->register(XAJAX_FUNCTION, "login_member");
  121. if($sys->get['ope'] == "logout"){
  122. if (!$c->iflogin()){
  123. $sys->prompt("jump",$CONFIGURE['common']['control_index']."?act=login",$LANGUAGE['s']['login']['no_need_logout']);
  124. }
  125. $c->destroy();
  126. $ac->destroy();
  127. $sys->prompt("jump", $CONFIGURE['common']['control_index']."");
  128. }else{
  129. // check login
  130. if( $MEMBER['iflogin'] == "1" ) {
  131. $sys->prompt("failed",sprintf($LANGUAGE['s']['login']['already_login'],$MEMBER['username']));
  132. }
  133. /////
  134. // outside prompt message
  135. if(!empty($sys->get['msg']) || !empty($sys->get['ret'])) {
  136. $sys->prompt("jump",$CONFIGURE['common']['control_index']."?act=login", $sys->get['msg'], $sys->get['ret']);
  137. }
  138. //////
  139. }
  140. $public_var['page_place'][] = $LANGUAGE['s']['login']['page_place'];
  141. ?>