Skip to main content

What is hashing

Hashing is a process that transforms plaintext data (such as passwords) into a fixed-length string via a one-way transformation. The same input always produces the same hash, but you cannot recover the original plaintext from the hash. Laravel’s Hash facade supports the bcrypt and Argon2 hashing algorithms for securely storing passwords.

Algorithm comparison

The bcrypt “work factor” controls the time it takes to generate a hash. The slower the hash, the greater the resistance to brute-force attacks. As hardware gets faster, you can maintain security by increasing the work factor.

Hashing and verification flow


Configuration

By default, Laravel uses the bcrypt driver. You can change it via the HASH_DRIVER environment variable.
To customize hashing configuration, publish the configuration file with config:publish.
After publishing, you can change defaults like the work factor in config/hashing.php.

Basic usage

Hashing a password

Passing the plaintext password to Hash::make() returns a hash value. Store this hash value in the database.
Store the hash value in the database, but never store plaintext passwords.

Adjusting the bcrypt work factor

You can adjust the compute cost of hash generation via the rounds option. A larger value is more secure but also takes longer to process. The default value (12) is appropriate for most applications.

Adjusting Argon2 parameters

When using Argon2, you can adjust the compute cost via the memory, time, and threads options.
For details on Argon2 options, see the official PHP documentation.

Verifying passwords

Use Hash::check() to verify whether a plaintext password matches a stored hash. This is a typical use in login handling.
When you use Auth::attempt(), this is done automatically, so you don’t need to call it directly. Hash::check() is useful when you need to manually verify the current password.

Determining when to rehash

Use Hash::needsRehash() to check whether a hash was generated with a work factor different from the current configuration. Use it to update existing hashes to the new configuration after changing the work factor.
Here’s an example of rehashing on successful login.
Periodically review the work factor as hardware improves to maintain security. By leveraging needsRehash(), you can update passwords naturally at the moment a user logs in.

Hash algorithm verification

By default, Hash::check() verifies that a hash was generated by the currently configured algorithm. If the algorithm is different, a RuntimeException is thrown. This prevents attacks that tamper with the hash algorithm. When migrating algorithms and needing to support multiple algorithms simultaneously, you can disable this verification by setting HASH_VERIFY to false.
Setting HASH_VERIFY=false disables algorithm verification. Only use it during a migration period and return to true (the default) once migration is complete.

Summary

Next steps

Authentication introduction

Learn the full picture of authentication, including implementing login handling using Hash::check().
Last modified on July 13, 2026