includes\modules\integrates\ecshop.php

2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家



遇到的问题:想让老系统注册用户也可以在Ecshop中登陆,可老系统注册用户的密码是采用 md5 16位加密的,所以想在数据库ecs_users表里增加一个“password16”字段,导入老系统md5密码,让ecshop用户登陆时密码和ecs_users表里password或password16字段里的值有任一匹配就能登陆进去

因为懂其它程序语言,不懂php,琢磨了半天,感觉要实现这一功能应该修改includes\modules\integrates\ecshop.php (可能是这个文件,呵)


希望那位老师能在百忙之中,帮帮忙,写出具体实现代码,不胜感谢~

附:includes\modules\integrates\ecshop.php文件源码:(可能需要修改107行)

  1. <?php

  2. if (!defined('IN_ECS'))
  3. {
  4. die('Hacking attempt');
  5. }

  6. /* 模块的基本信息 */
  7. if (isset($set_modules) && $set_modules == TRUE)
  8. {
  9. $i = (isset($modules)) ? count($modules) : 0;

  10. /* 会员数据整合插件的代码必须和文件名保持一致 */
  11. $modules[$i]['code'] = 'ecshop';

  12. /* 被整合的第三方程序的名称 */
  13. $modules[$i]['name'] = 'ECSHOP';

  14. /* 被整合的第三方程序的版本 */
  15. $modules[$i]['version'] = '2.0';

  16. /* 插件的作者 */
  17. $modules[$i]['author']= 'ECSHOP R&D TEAM';

  18. /* 插件作者的官方网站 */
  19. $modules[$i]['website'] = 'http://www.ecshop.com';

  20. return;
  21. }

  22. require_once(ROOT_PATH . 'includes/modules/integrates/integrate.php');
  23. class ecshop extends integrate
  24. {
  25. var $is_ecshop = 1;

  26. function __c**truct($cfg)
  27. {
  28. $this->ecshop($cfg);
  29. }

  30. /**
  31. *
  32. *
  33. * @accesspublic
  34. * @param
  35. *
  36. * @return void
  37. */
  38. function ecshop($cfg)
  39. {
  40. parent::integrate(array());
  41. $this->user_table = 'users';
  42. $this->field_id = 'user_id';
  43. $this->ec_salt = 'ec_salt';
  44. $this->field_name = 'user_name';
  45. $this->field_pass = 'password';
  46. $this->field_email = 'email';
  47. $this->field_gender = '**';
  48. $this->field_bday = 'birthday';
  49. $this->field_reg_date = 'reg_time';
  50. $this->need_sync = false;
  51. $this->is_ecshop = 1;
  52. }


  53. /**
  54. *检查指定用户是否存在及密码是否正确(重载基类check_user函数,支持zc加密方法)
  55. *
  56. * @accesspublic
  57. * @paramstring$username用户名
  58. *
  59. * @returnint
  60. */
  61. function check_user($username, $password = null)
  62. {
  63. if ($this->charset != 'UTF8')
  64. {
  65. $post_username = ecs_iconv('UTF8', $this->charset, $username);
  66. }
  67. else
  68. {
  69. $post_username = $username;
  70. }

  71. if ($password === null)
  72. {
  73. $sql = "SELECT " . $this->field_id .
  74. " FROM " . $this->table($this->user_table).
  75. " WHERE " . $this->field_name . "='" . $post_username . "'";

  76. return $this->db->getOne($sql);
  77. }
  78. else
  79. {
  80. $sql = "SELECT user_id, password, salt,ec_salt " .
  81. " FROM " . $this->table($this->user_table).
  82. " WHERE user_name='$post_username'";
  83. $row = $this->db->getRow($sql);
  84. $ec_salt=$row['ec_salt'];
  85. if (empty($row))
  86. {
  87. return 0;
  88. }

  89. if (empty($row['salt']))
  90. {
  91. if ($row['password'] != $this->compile_password(array('password'=>$password,'ec_salt'=>$ec_salt)))
  92. {
  93. return 0;
  94. }
  95. else
  96. {
  97. if(empty($ec_salt))
  98. {
  99. $ec_salt=rand(1,9999);
  100. $new_password=md5(md5($password).$ec_salt);
  101. $sql = "UPDATE ".$this->table($this->user_table)."SET password= '" .$new_password."',ec_salt='".$ec_salt."'".
  102. " WHERE user_name='$post_username'";
  103. $this->db->query($sql);

  104. }
  105. return $row['user_id'];
  106. }
  107. }
  108. else
  109. {
  110. /* 如果salt存在,使用salt方式加密验证,验证通过洗白用户密码 */
  111. $encrypt_type = substr($row['salt'], 0, 1);
  112. $encrypt_salt = substr($row['salt'], 1);

  113. /* 计算加密后密码 */
  114. $encrypt_password = '';
  115. switch ($encrypt_type)
  116. {
  117. case ENCRYPT_ZC :
  118. $encrypt_password = md5($encrypt_salt.$password);
  119. break;
  120. /* 如果还有其他加密方式添加到这里*/
  121. //case other :
  122. //----------------------------------
  123. //break;
  124. case ENCRYPT_UC :
  125. $encrypt_password = md5(md5($password).$encrypt_salt);
  126. break;

  127. default:
  128. $encrypt_password = '';

  129. }

  130. if ($row['password'] != $encrypt_password)
  131. {
  132. return 0;
  133. }

  134. $sql = "UPDATE " . $this->table($this->user_table) .
  135. " SET password = '".$this->compile_password(array('password'=>$password)) . "', salt=''".
  136. " WHERE user_id = '$row[user_id]'";
  137. $this->db->query($sql);

  138. return $row['user_id'];
  139. }
  140. }
  141. }


  142. }

  143. ?>
复制代码