public function changepwd() { if ($this->_post('password')) { $old_password = $this->_post('password'); $new_password = $this->_post('new_password'); if ($new_password === $this->_post('new_password_confirm')) { $M = M('User'); $password = $M->where('id=' . session('userid'))->getField('password'); $encrypt_password = md5Encrypt($old_password); if (isset($password) && $password === $encrypt_password) { if (!empty($password)) { $result = $M->where('id=' . session('userid'))->setField('password', md5Encrypt($new_password)); $this->msg = 'Success'; } } else { $this->msg = '密码错误'; } } else { $this->msg = '两次密码输入不一致'; } } else { } $this->display(); }
public function signup() { if ($this->isGet()) { $this->display(); exit; } session('errors', 0); session('errors', session('errors') + 1); if (session('errors') > 3 && !$this->recaptcha_valiaute()) { $this->display(); exit; } $User = D("User"); $username = $this->_post('uname'); $email = $this->_post('mail'); $password = $this->_post('pwd'); //Verify $msg = (empty($username) ? 'username ' : '') . (empty($email) ? 'email ' : '') . (empty($password) ? 'password ' : ''); if (!empty($msg)) { $msg .= 'shuould be input.'; } else { if ($password != $this->_post('confirm')) { $msg = "The password didn't match."; } else { $id = $User->getFieldByUsername($username, 'id'); if (!empty($id)) { $msg = "Username already exists."; } else { $email = $User->getFieldByEmail($email, 'id'); if (!empty($email)) { $msg = "{$email},Email already exists."; } } } } if (!empty($msg)) { $this->username = $username; $this->email = $email; $this->msg = $msg; $this->display(); exit; } $result = $User->create(); if ($result) { $User->password = md5Encrypt($password); $User->add(); $this->success('Register Success.', U('Login/index'), 3); } else { $this->error('Register Fail.', U('Login/signup')); } $this->display(); }