Implement change password functionality in feathersjs project

228 Views Asked by At

I am actually trying to implement change password functionality in my feathersjs project. what basically I am trying to do is, I am receiving input from user (old-password and new-password), first I have to compare the hash of this old-password with the hash of the password already stored in database, but when I generate the hash (using hashPassword() hook in feathers) of this old-password field provided by user and compare it with the password hash in database, I am getting negative response, even if I am using the same password (plain text of password). The problem here is I am getting different hashes for the same string(because it is using salts internally) when I am using this hashPassword() function. So I am not able to compare the password hashes. So, is there a function or something like that, that I can use to compare the string with hash or hash with hash.

>       async function checkPassword(context) { 
>       //already hashed. I also have the plain text of this string
>       const oldPassword = context.data.oldPassword; 
>       // const newPassword = context.data.newPassword;
>       //get the current logged-in users password(hash) from 
>       //database
>       const user = await app.service('users').get(context.id);
>       console.log('DB: ', user.password);
>     
>       if (oldPassword === user.password) {
>         //allowed to change password
>         return true;
>       
>     
>       } else {
>         //not allowed to change password
>         return false;
>       }
>     
>     }
0

There are 0 best solutions below