Auth ORM을 사용하면 암호를 변경하기 전에 이전 암호가 올바른지 어떻게 알 수 있습니까? find_salt 메소드를 사용하는 이전 버전의 Kohana에 대한 코드를 보았지만 버전 3.3에서는 더 이상 적용 할 수 없습니다.Kohana 3.3 암호를 변경하기 전에 이전 암호를 확인하십시오.
아이디어가 있으십니까?
Auth ORM을 사용하면 암호를 변경하기 전에 이전 암호가 올바른지 어떻게 알 수 있습니까? find_salt 메소드를 사용하는 이전 버전의 Kohana에 대한 코드를 보았지만 버전 3.3에서는 더 이상 적용 할 수 없습니다.Kohana 3.3 암호를 변경하기 전에 이전 암호를 확인하십시오.
아이디어가 있으십니까?
사용하여이 검증 클래스를 할 수있는 더 좋은 방법이 있습니다 :
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
}
}
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.
}
완벽한, 감사 –