如何通过哈希使确认密码验证成为cakephp

如何通过哈希使确认密码验证成为cakephp,php,validation,cakephp,hash,sha256,Php,Validation,Cakephp,Hash,Sha256,我使用的是cakephp 2.xx,我想在进入数据库之前用sha256对密码进行哈希运算, 在此之前,我想在我的表单输入中输入验证值密码,验证将检查密码输入并重新确认密码是否匹配,如果在我的控制器中,当表单捕获验证时,密码将自动散列 if ($this->request->data['Driver']['password'] != $this->request->data['Driver']['confirm_password']) { $this->r

我使用的是cakephp 2.xx,我想在进入数据库之前用sha256对密码进行哈希运算, 在此之前,我想在我的表单输入中输入验证值密码,验证将检查密码输入并重新确认密码是否匹配,如果在我的控制器中,当表单捕获验证时,密码将自动散列

if ($this->request->data['Driver']['password'] != $this->request->data['Driver']['confirm_password']) {
      $this->request->data['Driver']['password'] = hash('sha256',$this->request->data['Driver']['password']);
}
必要的是,表单没有捕获验证时的密码散列,那么如何在模型中进行验证呢

提前感谢。

在您的模型中(Driver.php)

验证

<?php 
    public $validate = array(

        'password' => array(
            'notempty' => array(
                'rule' => array('notempty'),                            
            ),
            'password_confirm'=>array(
                'rule'=>array('password_confirm'),
                'message'=>'Password Confirmation must match Password',                         
            ),    
        ),      
    );
?>

自定义验证规则

<?php 
    public function password_confirm(){ 
        if ($this->data['Driver']['password'] !== $this->data['Driver']['password_confirmation']){
            return false;       
        }
        return true;
    }
?>

哈希,但我认为最好选择AuthComponent

<?php 
    public function beforeSave($options = array()) {        
        $this->data['Driver']['password'] = hash('sha256',$this->data['Driver']['password']);   
        return true;        
    }
?>

它是整体描述,您可能需要在模型(Driver.php)中修改它的某些部分

验证

<?php 
    public $validate = array(

        'password' => array(
            'notempty' => array(
                'rule' => array('notempty'),                            
            ),
            'password_confirm'=>array(
                'rule'=>array('password_confirm'),
                'message'=>'Password Confirmation must match Password',                         
            ),    
        ),      
    );
?>

自定义验证规则

<?php 
    public function password_confirm(){ 
        if ($this->data['Driver']['password'] !== $this->data['Driver']['password_confirmation']){
            return false;       
        }
        return true;
    }
?>

哈希,但我认为最好选择AuthComponent

<?php 
    public function beforeSave($options = array()) {        
        $this->data['Driver']['password'] = hash('sha256',$this->data['Driver']['password']);   
        return true;        
    }
?>

它是总体描述,您可能需要修改其中的某些部分