I had a really simple need where every user should get a random X number of characters password in a Laravel application. I was sure of Google having a simple one-liner code result and that would make my day, but none.
Let's say we want to generate 12-character length password. So here is simple code to achieve it:
$hashedRandomPassword = Hash::make(str_random(12));
Do not forget to add the
Hash facade in order to use
make method from it:
Or, you can also use
$hashedRandomPassword = bcrypt(str_random(12));
That's it for today. Hope you liked this small tip for generating random passwords in Laravel.
Happy Coding! :)