In laravel I want to check if user enter current password than check with that password which is store in database in that user data. If correct than continue otherwise give message Password is incorrect.
I am new in laravel so not getting exact idea for this.
Thanks in advance.
$('#pwd').blur(function(){
var oldpwd=$('#pwd').val();
var uid = $('#id').val();
console.log(uid);
if(oldpwd != "")
{
$.ajax({
url : "{{ url/profile/checkOldPwd}}",
data : { oldpwd:oldpwd , uid:uid },
type : "POST",
success : function(data) {
if(data == 0){
$("#msg-old").show();
$("#msg-old").html("Password is Incorrect!");
$("#pwd").val("");
$("#pwd").focus();
}
else
{
$("#msg-old").hide();
$("#msg-old").html("");
}
}
});
}
});
You cannot decrypt laravel password hash which is bcrypt. You can change it with new password. You can get the hashedPassword like this: $hashedPassword = Auth::user()->getAuthPassword();
In your form. blade, ensure that the password input field has a name attribute of name="password" -> it has to be password , Also, add an attribute of name="password_confirmation" to the Confirm Password text input box, and it will work.
As Hiren has mentioned you can use the default registered hasher as that is passed to the specific UserProvider used. The default is Illuminate\Hashing\BcryptHasher
.
You can use it a couple of ways:
$user = User::find($id);
$hasher = app('hash');
if ($hasher->check('passwordToCheck', $user->password)) {
// Success
}
$user = User::find($id);
if (Hash::check('passwordToCheck', $user->password)) {
// Success
}
password_verify
also works. However that works because the default hashing algorithm it uses is bcrypt.if (password_verify('passwordToCheck', $user->password)) {
// Success
}
you can use hash:check method.
create password using hash:
$password = Hash::make('secret');
check password:
if (Hash::check('secret', $hashedPassword))
{
// The passwords match...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With