Laravel password verification for change

In Laravel 4, I have the following condition to make sure the user has correctly inserted their current password, and if so, do something.

Here is the code:

if(Auth::user()->password==Hash::make(Input::get('old_password')) ) { echo 'done'; } 

But this does not meet the condition. Why?

+6
source share
2 answers

Because part of the hash is salt that will never be the same. Instead, you need to use the Hash::check method, which knows what to do correctly. So that...

 if (Hash::check(Input::get('old_password'), Auth::user()->password)) { echo 'done'; } 
+21
source

Auth :: validate is also an option if your ultimate goal is to make sure that the user is who he / she is speaking.

 $credentials = ['email' => Auth::user()->email, 'password' => Input::get('old_password')]; if (Auth::validate($credentials)) { echo "Successful"; } 
+2
source

All Articles