Header image
Argon 2 in Laravel 5.7

Password protection with Argon 2 in Laravel 5.7

January 24, 2019PHP

Argon 2 in Laravel or PHP 7 is one of the most modern technologies to protect passwords . I am not saying it is the best, but it is one of the safest to date.

I am sure that you observed in a lot of web applications, some parts require you to re-enter your password in order to proceed further or perform a desired action. As an example, if you are working as a Freelancer on Upwork, you might be seen that you need to re enter your password, if you try to change anything from your account setting options.

This strategy works well as a double check and provides your application an extra layer of security.

By the way, if you don’t know about Argon 2, then I recommend you to learn Argon2 password protection from this article. And if you are familiar with how to use Argon 2 in Laravel 5.7, let’s go with this article.

A short Note

[su_list icon=”icon: check-circle” icon_color=”#4e993b”]

  • In order to be able to use Argon 2 in Laravel, your server need to have installed PHP version 7.2 or higher.
  • The Argon2id library requires PHP 7.3 or higher.


Password protection in Laravel 5.7 with Argon 2 in PHP 7.3

If you want to set up the security libraries for Byescript or Argon2 passwords, you can do within the hashing.php file, which is located in the config folder.

├── app/
├── bootstrap/
├── config/
├── app.php
├── auth.php
├── ...
├── hashing.php //Argon library configuration file
├── ...
├── database
├── public
├── resources
├── ...

With Argon 2 you can improve the security of your project passwords in PHP. In this article I will show you using Laravel 5.7 for both administrators and public users with a password.

In order to use Argon 2 in your Laravel 5.7 project, you must install the Hash Facade and pass the make Method to the password, let’s see an example below.

'password' => Hash::make($request->newPassword)

That’s all. Don’t forget that Laravel is a Framework for Agile project development with PHP, you don’t need to do too much.

If you want to customize Argon 2 in the same code, you can do it when you pass the make Method to the password and configure the data in memory, time and threads.

$hashed = Hash::make('password', [
'memory' => 1024,
'time' => 2,
'threads' => 2,

You can verify that the password which user will enter for his account is corresponded to a specific hash with the check method.

if (Hash::check('plain-text', $hashedPassword)) {
// Passwords match...

You also can check with the needsRehash function if memory, time and thread data have been modified since a password was hashed.

if (Hash::needsRehash($hashed)) {
$hashed = Hash::make('plain-text');

As you can see it is not very complicated to use Argon 2 in Laravel 5.7

Thank for stopping by and wishing you best of luck.


Follow us on our social media networks, so that you don’t miss our next articles.