Php 正在从数据库获取(而不是解密)md5密码

Php 正在从数据库获取(而不是解密)md5密码,php,mysql,cakephp,Php,Mysql,Cakephp,我一直在做一个密码设置,每当用户想要更新他们的密码时,他们都不能将新密码更新为与以前/当前密码相同的密码。数据库中的密码存储为md5格式 所以我要做的是首先将新的输入密码转换为md5,并将其与数据库中的密码进行比较。这可能是一个小错误,但经过数小时的尝试和谷歌搜索,我仍然无法获取数据库中的密码进行比较 我想这可能是参数。我是一个新手,还在学习,如果这对像男人这样的专家来说太简单了,我很抱歉。提前感谢您抽出时间 这是我的模型 控制器 看法 问题是您获取数据的方式。它将作为$result['Mode

我一直在做一个密码设置,每当用户想要更新他们的密码时,他们都不能将新密码更新为与以前/当前密码相同的密码。数据库中的密码存储为md5格式

所以我要做的是首先将新的输入密码转换为md5,并将其与数据库中的密码进行比较。这可能是一个小错误,但经过数小时的尝试和谷歌搜索,我仍然无法获取数据库中的密码进行比较

我想这可能是参数。我是一个新手,还在学习,如果这对像男人这样的专家来说太简单了,我很抱歉。提前感谢您抽出时间

这是我的模型

控制器

看法


问题是您获取数据的方式。它将作为$result['Model']['fieldsname']返回。因此,在进行比较时,您必须注意这一点。更改函数getUserPassword-

而在控制器中—

$data = $this->request->data;
$uid = $data['uid'];
$new_pwd ='';
if($continue == true) {
    if(md5($new_pwd) == $this->users->getUserPassword($uid)) {
        $continue = false;
        $return_msg = "New password cannot be the same as the old password";            
    }
}
$new_pwd应该是请求数据中的new_密码字段

    $data = $this->request->data;
    $uid = $data['uid'];
    $new_pwd ='';
   if($continue == true) {
        if(md5($new_pwd) == $this->users->getUserPassword($uid)) {
            $continue = false;
            $return_msg = "New password cannot be the same as the old password";            
        }
    }
<tr>
    <td><input id="new_pwd" type="password" name="new_password"></input></td>
</tr>
public function getUserPassword($uid) {
    $result = $this->field('users.upwd', array('users.uid' => $uid)); //will return the value in db field
    return $result;    
}
$data = $this->request->data;
$uid = $data['uid'];
$new_pwd ='';
if($continue == true) {
    if(md5($new_pwd) == $this->users->getUserPassword($uid)) {
        $continue = false;
        $return_msg = "New password cannot be the same as the old password";            
    }
}