Hashing converts plain-text data such as passwords into a fixed-length string through a one-way transformation.
The same input always produces the same hash, but you cannot recover the original plain text from a hash.Laravel’s Hash facade supports bcrypt and Argon2 hashing algorithms for secure password storage.
Work factor (rounds) controls computation cost. Default driver
General web applications
argon2i
Configurable memory, time, and threads. Resistant to side-channel attacks
High-security scenarios
argon2id
Hybrid of argon2i and argon2d. Recommended by the PHC
New projects using Argon2
The bcrypt “work factor” controls how long it takes to generate a hash. A slower hash increases resistance to brute-force attacks. As hardware becomes faster, you can raise the work factor to maintain security.
Use the rounds option to control the computation cost of hash generation. Higher values are more secure but slower.
The default value of 12 is appropriate for most applications.
Use Hash::check() to verify that a plain-text password matches a stored hash.
This is typically used inside login logic.
use Illuminate\Support\Facades\Hash;if (Hash::check($request->password, $user->password)) { // Passwords match} else { // Passwords do not match}
When using Auth::attempt(), this comparison happens automatically. You call Hash::check() directly when you need to manually verify a password, such as confirming the current password before a change.
// Confirm current password before allowing a password changeif (! Hash::check($request->current_password, $request->user()->password)) { return back()->withErrors(['current_password' => 'The current password is incorrect.']);}
Hash::needsRehash() checks whether the work factor used to hash a password differs from the current configuration.
Use this to update existing hashes when you raise the work factor.
use Illuminate\Support\Facades\Hash;if (Hash::needsRehash($user->password)) { $user->update([ 'password' => Hash::make($plainTextPassword), ]);}
A common pattern is to rehash on successful login.
// Rehash during loginif (Auth::attempt($credentials)) { if (Hash::needsRehash(Auth::user()->password)) { Auth::user()->update([ 'password' => Hash::make($credentials['password']), ]); } return redirect()->intended('/dashboard');}
Review your work factor periodically as hardware improves. Using needsRehash() during login lets you update passwords transparently without requiring users to take any action.
By default, Hash::check() verifies that the given hash was generated using the application’s configured algorithm.
If the algorithms differ, a RuntimeException is thrown.This protects against hash algorithm manipulation attacks.If you need to support multiple algorithms simultaneously — for example, during a migration from one algorithm to another — you can disable this verification by setting HASH_VERIFY to false.
# .envHASH_VERIFY=false
Setting HASH_VERIFY=false disables algorithm verification. Use this only during a migration period and restore it to true (the default) once the migration is complete.