如何通过哈希确认密码验证cakephp
how to make confirm password validation cakephp with hashing it
我正在使用 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']);
}
必然地,密码散列在表单完全没有 catch 验证时,那么如何在我的模型中进行验证?
提前致谢。
在您的模型中(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;
}
?>
这是总体描述,您可能需要修改其中的某些部分
我正在使用 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']);
}
必然地,密码散列在表单完全没有 catch 验证时,那么如何在我的模型中进行验证?
提前致谢。
在您的模型中(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;
}
?>
这是总体描述,您可能需要修改其中的某些部分