How to generate random password in Laravel

This is a really really short one. I just needed to generate a random password for a user and noticed that Google doesn’t really give a one-line answer, which is really simple.

Firstly, how to generate random string – Laravel has a helper called str_random($length). In terms of saving hashed password to database, we use Hash::make($password).

So the end result for generating 8-symbol length password looks as simple as this:

$hashed_random_password = Hash::make(str_random(8));

Of course, don’t forget:

use Illuminate\Support\Facades\Hash;

Generated password can look like:


And hash is something like:


That’s it for now, hope it’s a useful short tip.

Like our articles?
Check out our Laravel online courses!


  1. The instruction above is suitable for those who are already good in coding but is not a clear instruction for beginners. Beginner doesn’t understand where to put the code, where to start and where to end.

    • I agree, but my articles are not suitable for complete beginners. Otherwise I would have to start and end the articles with building a full Laravel project.


Please enter your comment!
Please enter your name here