2016-08-12 7 views
0

cakephp 2.xx를 사용하고 있는데, 전에 sha256 암호를 해싱하고 싶습니다. 전에 양식 입력에 유효성 검사 암호를 입력하고 싶습니다. 유효성 검사 암호를 입력하고 다시 확인 암호가 일치 확인하는 내 컨트롤러에서 경우 때 폼 잡기 검증, 암호가 자동으로 할 때 양식없이 캐치 유효성을 전혀, 그래서 어떻게 내가 할 수있는,암호 해독 방법 cakephp 확인 방법 확인

if ($this->request->data['Driver']['password'] != $this->request->data['Driver']['confirm_password']) { 
     $this->request->data['Driver']['password'] = hash('sha256',$this->request->data['Driver']['password']); 
} 

반드시 암호 해시를 해시 내 모델에서 유효성 검사를할까요?

감사의 말 전진. 모델에서

답변

3

(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; 
    } 
?> 

해싱,하지만 난 더 나은

<?php 
    public function beforeSave($options = array()) {   
     $this->data['Driver']['password'] = hash('sha256',$this->data['Driver']['password']); 
     return true;   
    } 
?> 
AuthComponent을 선택할 수 있다고 생각

전체적인 설명이므로 아마도 일부 부분을 수정해야 할 것입니다.

+0

고맙습니다. –