Reputation: 43
in my application, I have a default password (1234 for example) for all users I create, when the user login for the first time he will be asked to change that password
my goal is when a user login I want to check if his password equal to that default value (1234) if that's true I redirect him to the reset page if not I 'll do nothing
so my question is how to check that user's password if it's equal or not to a value I have?
Upvotes: 2
Views: 1163
Reputation: 43
I have found an answer on StackOverflow that helped me a lot You can use it a couple of ways:
Out of the container
$user = User::find($id);
$hasher = app('hash');
if ($hasher->check('passwordToCheck', $user->password))
{
// Success
}
Using the Facade
$user = User::find($id);
if (Hash::check('passwordToCheck', $user->password))
{
// Success
}
Out of interest using the generic php function password_verify also works. However that works because the default hashing algorithm it uses is bcrypt.
if (password_verify('passwordToCheck', $user->password))
{
// Success
}
Upvotes: 2