How do i verify argon2 hash


#1

Within my project i’ve managed to register a user and hash their password using the argon2 hashing driver. Which i can verify looking at my database:

However, when i go to logon as a user i get in the terminal: Cannot verify user password. My thought would be that the hash isn’t being verified.

Here is my code within the ‘User’ model within the ‘Hooks’ folder:

UserHook.hashPassword = async (userInstance) => {
  if (userInstance.password) {
    userInstance.password = await argon2.hash(userInstance.password)
  }
}


How would i verify the hash when a user logs on

Any help would be appreciated :slight_smile:


#2

I believe when the user tries to login, they will surely provide you with their password. So all you need to do is use their provided password and match it with their is existing hashed password.

Apart from that, you are simply avoiding the in builds of AdonisJs, which you should not.

  1. Their is no need to use argon2 module directly. You must use the inbuilt Hash provider, which also supports argon https://adonisjs.com/docs/4.1/encryption-and-hashing#_hashing_values.

  2. Their is no need to manually handle the management of user password verification, you must used the inbuilt auth module for that.

Finally, read the documentation carefully, and use what’s available


#3

Thanks for your reply! After figuring it out and taking your advice. I can confrim this worked :slight_smile: Thanks again!