2014-06-13 8 views

답변

1

사용하여이 검증 클래스를 할 수있는 더 좋은 방법이 있습니다 :

if($post = $this->request->post()) { 
    $user = Auth::instance()->get_user(); 

    $validation = Validation::factory($post) 
     ->rule('old_password', array(Auth::instance(), 'check_password')); 

    // Rules for password (model rules applies after hash) 
    $extra_rules = Validation::factory($post) 
     ->rule('password', 'not_empty') 
     ->rule('password', 'min_length', array(':value', 8)) 
     ->rule('password', 'matches', array(':validation', 'password', 'password_confirm')); 

    try { 
     if(!$validation->check()) { 
      throw new ORM_Validation_Exception('password', $validation); 
     } 
     $user->password = $post['password']; 
     $user->update($extra_rules); 
    }catch(ORM_Validation_Exception $e){ 
     // Handle errors 
    } 
} 
1

hash() 메서드를 사용하면 저장된 문자열과 비교 한 후 암호 문자열을 해시 할 수 있습니다.

$auth = Auth::instance(); 
$user = ORM::factory('user') 
    ->where('username', '=', 'User') 
    ->find(); 

if ($auth->hash($_POST['password']) == $user->password) 
{ 
    // Passwords match, change here. 
} 
else 
{ 
    // Passwords not match. 
} 
+0

완벽한, 감사 –