A quick way to change Password encryption method in Laravel 7

Muhammad Abad
3 min readJul 3, 2020

We are going to change Laravel’s Default encryption method for login and register. And what Laravel says about the authentication, The Laravel Hash facade provides secure Bcrypt and Argon2 hashing for storing user passwords. If you are using the built-in LoginController and RegisterController classes that are included with your Laravel application, they will use Bcrypt for registration and authentication by default. (Laravel Official).

So first we need to change in RegisterController.php file. You will see a method create.

And We have to add a function to provide a converted password or we can also write conversion code in the above method but we should use the function for each and every task.

Here we need to pass a string to this method and it will return an encrypted password and here we are using our own custom conversion as you can see.

So it’s done for the registration but now we have to do a little bit tricky thing to make it workable at the time of login.

So let’s deep dive into LoginController.php file and you will see a trait that is used by Laravel Framework to make authentication workable. And we need to change in AuthenticateUsers.php(trait class) file.

You will see a method with name attemptlogin()

And we are going to modify this one to make our login workable for stored encrypted passwords. Now we need to comment/remove the above snippet and write these lines of code.

And this is done now you can register and log in without following laravel’s encryption!

Before you go… Thanks for reading the article! If you enjoyed it, please don’t forget to show your appreciation by clicking the 👏 below!

I write about my professional experiences as a self-taught software developer, so click the follow button if this interests you!

--

--

Muhammad Abad

I’m Abad based from the India & I am working as a Software Developer. I specialize in building applications specific to the business needs of my clients.