[英]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']);
}
必然,當沒有捕獲時,密碼哈希值將全部驗證,那么如何在模型中進行驗證?
提前致謝。
在您的模型中(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;
}
?>
它是整體描述,您可能需要修改其中的某些部分
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.