密码和重新登录失败

时间:2012-03-08 02:15:20

标签: php cakephp cakephp-1.3 cakephp-2.0

我的身份验证有点问题,我可以更改用户的密码并将其保存到数据库中,但以后用户无法使用新密码登录, 这是登录程序的源代码

    $error = '';
    $this->User->set($this->data);
    if($this->Session->read($this->_userName)){
        $this->redirect('index');           
    }

    if(!empty($this->data)){
        if($this->User->validates($this->data)){
            $email = $this->data['User']['email_login'];                
            $password = md5($this->data['User']['password_login']);



                if($this->EwtUser->checkLogin($email,$password)){
                    $this->Session->write($this->_userName,$email);
                    //....
                    $this->redirect('index');
                }else{
                    $error  = 'Wrong Username or Password';             
        }

    }
    $this->set('error',$error);

我遇到的错误是我无法登录,它始终显示the password must be at least 4-32 characters long的消息。

以下是更改密码的源代码。

                    $data=array
        (
            'password'=>$user['User']['password']
        );
        if($data!=null)
        {
            $newpassword=$_POST['newPwd'];
            print_r($newpassword);
            $data=md5($newpassword);
            echo "<br/>";
            print_r($data);
            $userid = $user['User']['id'];
            try
            {
                $this->User->update_password($userid,$data);
            }
            catch(Exception $e){print_r(e.Message);}
        }

这是在模型中编写的update_password函数。

function update_password($userid, $newpass)
{
    $sql=sprintf("UPDATE users SET password='%s' WHERE id=%d",$newpass,$userid);
    $this->query($sql);
}

0 个答案:

没有答案