2017-07-28 145 views
0

我有一個編輯窗體,用戶將輸入他的新密碼,我想檢查輸入的密碼是否與數據庫中已存在的密碼匹配,如果它匹配,那麼它的錯誤「新密碼不能相同舊密碼「Laravel更新密碼驗證

這是我試過的代碼,它不適合我! :(

if(\Hash::check($request->password,$old_password)){ 
    return Redirect::back()->withErrors(['message', 'New Password cannot be same as old password']); 
} 
+0

你可以按照這個鏈接(https://開頭計算器。 com/questions/21495502/laravel-hashcheck-allways-return-false) –

+1

[Laravel Hash :: check()allways return false](https://stackoverflow.com/questions/21495502/laravel-hashcheck-allways -return-false) – DMC19

+0

@AddWebSolutionPvtLtd我試過這個解決方案,它不適用於我:( – user3315353

回答

0
if (Hash::check("ValueForEnteredpassword", "HashOldPassword")) { 
     //your code 
    } else { 
    //Your error message 
    } 
0

我想你可以嘗試這個例子:

if(!Hash::check($input['current_password'], $user->password)){ 

    dd('Return error with current passowrd is not match.'); 

}else{ 

    dd('Write here your update password code'); 

} 

希望這個例子爲您服務!!!