Authored by xiaowei

撞库

@@ -137,20 +137,26 @@ class PassportModel @@ -137,20 +137,26 @@ class PassportModel
137 137
138 /* 138 /*
139 * 重写递增计数 cache方法 139 * 重写递增计数 cache方法
140 - * $key cache-key 140 + * $key cache-key,递增存放变量
141 * $offset 递增偏移量 141 * $offset 递增偏移量
142 * $initValue 初始化值 142 * $initValue 初始化值
143 * $expiry 缓存时间 143 * $expiry 缓存时间
144 */ 144 */
145 - public static function increment($key, $offset = 1, $initValue = 0, $expire = 1800) 145 +
  146 + public static function increment($key, $timeKey, $offset = 1, $initValue = 0, $expire = 1800)
146 { 147 {
147 - //初始化key  
148 - if (!Cache::get($key)) {  
149 - Cache::set($key, $initValue, $expire); 148 + //有效期之外清除key
  149 + if (!Cache::get($timeKey) && Cache::get($key)) {
  150 + Cache::delete($key);
  151 + }
  152 + //初始化计时
  153 + if (!Cache::get($timeKey) && !Cache::get($key)) {
  154 + Cache::set($timeKey, TRUE, $expire);
  155 + Cache::set($key, $initValue);
150 } 156 }
151 - //增加偏移量  
152 - $cacheValue = intval(Cache::get($key))+$offset;  
153 - Cache::set($key, $cacheValue, $expire); 157 + //未过期则递增
  158 + $cacheValue = intval(Cache::get($key)) + $offset;
  159 + Cache::set($key, $cacheValue);
154 } 160 }
155 161
156 } 162 }
@@ -28,7 +28,7 @@ class LoginController extends WebAction @@ -28,7 +28,7 @@ class LoginController extends WebAction
28 if (!strstr($refer, 'http')) { 28 if (!strstr($refer, 'http')) {
29 $refer = SITE_MAIN . $refer; 29 $refer = SITE_MAIN . $refer;
30 } 30 }
31 - 31 +
32 if (!empty($refer)) { 32 if (!empty($refer)) {
33 $this->setCookie('refer', $refer); 33 $this->setCookie('refer', $refer);
34 } 34 }
@@ -70,7 +70,7 @@ class LoginController extends WebAction @@ -70,7 +70,7 @@ class LoginController extends WebAction
70 */ 70 */
71 public function authAction() 71 public function authAction()
72 { 72 {
73 - $data = array('code' => 400, 'message' => '您输入的密码及账户名不匹配,是否<a href="'.Helpers::url('/passport/back/index').'" target="_blank">忘记密码?</a>', 'data' => ''); 73 + $data = array('code' => 400, 'message' => '您输入的密码及账户名不匹配,是否<a href="' . Helpers::url('/passport/back/index') . '" target="_blank">忘记密码?</a>', 'data' => '');
74 do { 74 do {
75 /* 判断是不是AJAX请求 */ 75 /* 判断是不是AJAX请求 */
76 if (!$this->isAjax()) { 76 if (!$this->isAjax()) {
@@ -108,26 +108,43 @@ class LoginController extends WebAction @@ -108,26 +108,43 @@ class LoginController extends WebAction
108 */ 108 */
109 $ip = Helpers::getClientIp(); 109 $ip = Helpers::getClientIp();
110 $ipKey = md5('ip_signin_' . $ip); 110 $ipKey = md5('ip_signin_' . $ip);
  111 + $ipTimeKey = md5('ip_signin_time' . $ip);
111 $accountKey = md5('account_signin_' . $account); 112 $accountKey = md5('account_signin_' . $account);
112 - PassportModel::increment($ipKey, 1, 0, 3600); 113 + $accountTimeKey = md5('account_signin_time' . $account);
  114 + //cache初始化,非有效时间内清除次数,有效时间内叠加cache计数
  115 + if (!Cache::get($accountTimeKey) && Cache::get($accountKey)) {
  116 + Cache::delete($accountKey);
  117 + }
  118 + if (!Cache::get($accountTimeKey) && !Cache::get($accountKey)) {
  119 + Cache::set($accountTimeKey, true, 1800);
  120 + Cache::set($accountKey, 0);
  121 + }
  122 + if (!Cache::get($ipTimeKey) && Cache::get($ipKey)) {
  123 + Cache::delete($ipKey);
  124 + }
  125 + if (!Cache::get($ipTimeKey) && !Cache::get($ipKey)) {
  126 + Cache::set($ipTimeKey, true, 3600);
  127 + Cache::set($ipKey, 0);
  128 + }
113 $accountTimes = Cache::get($accountKey); 129 $accountTimes = Cache::get($accountKey);
114 - if ($accountTimes > 10) { 130 + $ipTimes = Cache::get($ipKey);
  131 + if ($accountTimes >= 10) {
115 $data = array('code' => 400, 'message' => '您的账号已被暂时锁定,请稍后再试', 'data' => ''); 132 $data = array('code' => 400, 'message' => '您的账号已被暂时锁定,请稍后再试', 'data' => '');
116 break; 133 break;
117 } 134 }
118 -  
119 - $ipTimes = Cache::get($ipKey);  
120 - if ($ipTimes > 100) { 135 + if ($ipTimes >= 100) {
121 $data = array('code' => 400, 'message' => '您尝试的次数过多,账号已被暂时锁定,请稍后再试', 'data' => ''); 136 $data = array('code' => 400, 'message' => '您尝试的次数过多,账号已被暂时锁定,请稍后再试', 'data' => '');
122 break; 137 break;
123 } 138 }
124 $data = LoginData::signin($area, $account, $password, $shoppingKey); 139 $data = LoginData::signin($area, $account, $password, $shoppingKey);
125 if (!isset($data['code']) || $data['code'] != 200 || !isset($data['data']['uid'])) { 140 if (!isset($data['code']) || $data['code'] != 200 || !isset($data['data']['uid'])) {
126 - PassportModel::increment($accountKey, 1, 0, 1800);  
127 - $data = array('code' => 400, 'message' => '您输入的密码及账户名不匹配,是否<a href="'.Helpers::url('/passport/back/index').'" target="_blank">忘记密码?</a>', 'data' => ''); 141 + Cache::set($accountKey, intval(Cache::get($accountKey)) + 1);
  142 + Cache::set($ipKey, intval(Cache::get($ipKey)) + 1);
  143 + $data = array('code' => 400, 'message' => '您输入的密码及账户名不匹配,是否<a href="' . Helpers::url('/passport/back/index') . '" target="_blank">忘记密码?</a>', 'data' => '');
128 break; 144 break;
129 } 145 }
130 146
  147 + //登录成功
131 $refer = $this->getCookie('refer'); 148 $refer = $this->getCookie('refer');
132 if (empty($refer) || strstr($refer, 'signin.html') || strstr($refer, 'passport/login/index')) { 149 if (empty($refer) || strstr($refer, 'signin.html') || strstr($refer, 'passport/login/index')) {
133 $refer = SITE_MAIN; 150 $refer = SITE_MAIN;
@@ -48,7 +48,8 @@ class RegisterController extends WebAction @@ -48,7 +48,8 @@ class RegisterController extends WebAction
48 $ip = Helpers::getClientIp(); 48 $ip = Helpers::getClientIp();
49 $data = array('code' => 400, 'message' => '', 'data' => ''); 49 $data = array('code' => 400, 'message' => '', 'data' => '');
50 $ipKey = md5('ip_checkmobile_' . $ip); 50 $ipKey = md5('ip_checkmobile_' . $ip);
51 - PassportModel::increment($ipKey, 1, 0, 3600); 51 + $ipTimeKey = md5('ip_checkmobile_time_' . $ip);
  52 + PassportModel::increment($ipKey,$ipTimeKey,1, 0, 3600);
52 $ipTimes = Cache::get($ipKey); 53 $ipTimes = Cache::get($ipKey);
53 do{ 54 do{
54 /* 判断是不是AJAX请求 */ 55 /* 判断是不是AJAX请求 */
@@ -60,7 +61,7 @@ class RegisterController extends WebAction @@ -60,7 +61,7 @@ class RegisterController extends WebAction
60 $data['message'] = '手机号码格式不正确'; 61 $data['message'] = '手机号码格式不正确';
61 break; 62 break;
62 } 63 }
63 - if ($ipTimes >= 500) { 64 + if ($ipTimes > 500) {
64 $data['message'] = '由于你IP受限无法注册'; 65 $data['message'] = '由于你IP受限无法注册';
65 break; 66 break;
66 } 67 }
@@ -130,7 +131,8 @@ class RegisterController extends WebAction @@ -130,7 +131,8 @@ class RegisterController extends WebAction
130 } 131 }
131 //发送代码 132 //发送代码
132 $sendCodeKey = md5('send_code_' . $area . '_' . $mobile); 133 $sendCodeKey = md5('send_code_' . $area . '_' . $mobile);
133 - PassportModel::increment($sendCodeKey, 1, 0, 3600); 134 + $sendCodeTimeKey = md5('send_code_time_' . $area . '_' . $mobile);
  135 + PassportModel::increment($sendCodeKey,$sendCodeTimeKey, 1, 0, 3600);
134 $sendCodeTimes = Cache::get($sendCodeKey); 136 $sendCodeTimes = Cache::get($sendCodeKey);
135 if ($sendCodeTimes > 50) { 137 if ($sendCodeTimes > 50) {
136 $data['message'] = '发送验证码太多'; 138 $data['message'] = '发送验证码太多';