mehalubozo's avatar

Decrypt password of user

Hi,

I need to decrypt the password of the user so I can help him login again. My application doesn't have a password reset flow. How can I do that?

This doesn't work

decrypt($user->password);
0 likes
1 reply
bobbybouwmann's avatar
Level 88

The passwords are "hashed" and not "encrypted". A hash always generates a unique string. You can compare two hashes, but you can't decrypt them. That's also how the login works. It creates a new hash and compares both hashes. But you will never know the actual value of the hash.

If you want to decrypt you need to encrypt something. However, this is not something you want to do with passwords. It's not secure at all.

If your user needs a new password I recommend you run php artisan tinker. Create a new bcrypt string with a random password and store that in the database.

$ php artisan tinker

 // Find by ID
$user = User::find(1);

$user->update(['password' => bcrypt('random-password')]);

Then the user can use the new password ;)

Ideally, it would be better to build a password reset flow of course.

1 like

Please or to participate in this conversation.