Hashing

Contents
Hash::make
Hash::check
Needs rehash
Bcrypt default note

Hash::make

Never store plain passwords, since any database leak would expose them all. Make turns a password into a one-way hash that cannot be turned back.

Save only the hash in the users table, with the Hash facade imported at the top.

use Illuminate\Support\Facades\Hash; $hash = Hash::make("secret123");

Hash::check

Login compares the typed password against the stored hash without ever decoding it. Check returns true only when the plain value matches the hash.

Branch on the result and keep timing details to the framework.

if (Hash::check("secret123", $user->password)) { echo "welcome back"; }

Needs rehash

Hash settings improve over time, so old hashes may use weaker options. NeedsRehash flags hashes that deserve a fresh make with current settings.

Check it at login, when the plain password is still at hand.

if (Hash::needsRehash($hash)) { $hash = Hash::make("secret123"); }

Bcrypt default note

Bcrypt is the default driver and a safe pick for most apps. Argon variants exist for servers with tuned memory settings.

Set the driver in the env file and keep make and check calls unchanged.

HASH_DRIVER=bcrypt

Next: Sanctum tokens

Article author: Arthur Isaev

Related articles
Development with PHP
What is Laravel and where it runs
Install Laravel
Your first route
Controllers
Blade basics
Blade advanced
Migrations
Eloquent models
Relationships
Query builder
Seeders and factories
Validation
Auth intro
Hand-rolled login
Middleware
Service container
Config and env
Artisan commands
Events and listeners
Queues
Mail
Cache
Sessions in Laravel
CSRF
Hashing
Sanctum tokens
API resources
Gates and policies
Notifications
Scheduler
Filesystem
Localization
Testing
HTTP tests
Collections
Carbon dates
Pagination
File uploads
Eloquent advanced
Transactions and locks
Deployment
Debugbar and dd
Broadcasting
Full-text search
Capstone: blog
Capstone: JSON API
Capstone: shop cart
Performance: kill N+1
Modern Laravel tour
Hero roadmap: the whole course on one page

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: