Trusted answers to developer questions

Basics of hashing in Laravel

Free System Design Interview Course

Many candidates are rejected or down-leveled due to poor performance in their System Design Interview. Stand out in System Design Interviews and get hired in 2024 with this popular free course.

widget

The Laravel Hash facade gives secure Bcrypt and Argon2 hashing to save client passwords. If you utilize one of the Laravel application starter packs, Bcrypt will be utilized for enlistment and authentication by default.

Bcrypt is a good choice for hashing passwords since its “work figure” is movable. This implies that the time it takes to generate a hash can be expanded with increased hardware power.

When hashing passwords, moderation is better. The longer an algorithm takes to hash a secret word, the longer it takes users to produce “rainbow tables” of all the conceivable hash values. These hash values will be used against applications.

How to perform basic hashing

  • To perform basic hashing in Laravel, we call the make() method on the Hash facade, like so:
<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;

  • Once you ensure that the necessary classes above are present, you then make your hash using the make() method on the hash facade, like so:

  • $hashPassword = Hash::make($request->('password'));

  • You then save the $hashPassword using whatever method you like in the database.

RELATED TAGS

hashing
php
laravel

CONTRIBUTOR

Chinweuba Elijah Azubuike
Did you find this helpful?