Reputation: 29
To change the password, i enter the current password.For the correct password also an error msg will be displayed
public function passwordupdate(Request $request){
$user=user::find(Auth::user()->id);
$validator=Validator::make($request->all(), [
//'password' => 'required|confirmed|min:6|max:14'
'cpassword'=> 'required|confirmed|min:6|max:14'
]);
if($validator->fails()){
return redirect()->back()->withErrors(['cpassword'=>'Please check the password you given']);
}else{
$user->cpassword=bcrypt($request->cpassword);
$user->save();
return redirect()->back();
}
}
Upvotes: 0
Views: 90
Reputation: 2366
First you need to use Illuminate\Support\Facades\Hash;
to check if the old password that was inputed by user you can use Hash::check()
. This function takes 2 parameters.
The first one is the plain string and the second one is the hashed password(old password).
You can retrieve old password by Auth::user()->password
so you if condition would be
if(Hash::check($request['oldpass'], $user->password)){
//insert the new password
Auth::user->update([
'password'=>bcrypt($data['newpass'])
]);
Auth::user->save();
}
P.S
Hash::check()
return true or false
Upvotes: 1
Reputation: 1835
Hash checking https://laravel.com/docs/5.3/hashing
if (Hash::check('plain_text_password', $hashedPassword))
{
// The passwords match...
}
Upvotes: 3
Reputation: 163798
You may use Hash::check()
method. For example, if you want to compare entered password with current user's one:
if (Hash::check($request->password, auth()->user()->password) {
// Entered password is correct.
Upvotes: 0