public function doIndex_BoxPost() { $rc['login'] = bus('post')['login']; $rc['password'] = bus('post')['password']; $rc['groupId'] = intval(bus('post')['group']); $rc['des'] = bus('post')['des']; //addslashes()和stripslashes() //监测空值 if (empty($rc['login']) || empty($rc['login'])) { echo json_encode(['code' => -200, 'msg' => '用户名或密码空']); exit; } //监测重复 $login = saddslashes($rc['login']); $sql = "select count(*) from user where login = '******'"; $num = sapp('db')->getone($sql); if ($num) { echo json_encode(['code' => -200, 'msg' => '该用户名存在']); exit; } //hash $rc['password'] = shamhash($rc['password']); //-------------------------------------------------------- $rc = saddslashes($rc); sapp('db')->autoExecute('user', $rc, 'INSERT'); //-------------------------------------------------------- echo json_encode(['code' => 200, 'msg' => '-']); }
public function cookies() { $userlogin = sapp('Cookies')->get('userlogin'); $logintime = sapp('Cookies')->get('logintime'); $sccheck = sapp('Cookies')->get('sccheck'); if (shamhash($userlogin, $logintime) == $sccheck) { //验证通过 返回数据 $res = $userlogin; } else { $res = null; } return $res; }
public function doLoginPOST() { $password = bus('post')['password']; $userlogin = bus('post')['userlogin']; $user = geter('user.login.' . $userlogin); if (empty($user)) { echo json_encode(['code' => -200, 'msg' => '该用户不存在']); exit; } if (!$user['active']) { echo json_encode(['code' => -200, 'msg' => '不是有效用户']); exit; } //成功记录数据进入cookie //记录信息 $tm = time(); $sccheck = shamhash($userlogin, $tm); sapp('cookies')->set('userlogin', $userlogin); sapp('cookies')->set('logintime', $tm); sapp('cookies')->set('sccheck', $sccheck); echo json_encode(['code' => 200, 'msg' => 'ok']); }