0

Every time I try to login bcrypt compare returns false but the registration works.

Here is the code for login :

async function init(passport){
const authenticateUser = async (email,password,done) => {
const user = await User.findOne({email : email})

if(user === null) return done(null,false,{message : "Email and Password do not match"});

try{
    const isPasswordMatch = await bcrypt.compare(password,user.password);
    console.log(isPasswordMatch);
    if(isPasswordMatch) return console.log("Up and running");
    done(null,false,{message : "Password"});
}
catch(error){done(error)}
}


}

module.exports = init;

Note that I am using passportjs library and excluded the code for it but I had this problem before I added it

Winston Brown
  • 97
  • 1
  • 5
  • If you log into the database, and run the findOne do you find the credentials, and are those the same type? Also, if for some reason the email is not unique, you may be getting a different user. Check those out. – Minsky Nov 13 '20 at 00:40
  • Good idea but I did just checked and all was good the only problem was when I used the hashed string to find the user it couldn't find it – Winston Brown Nov 13 '20 at 01:06
  • uhm...Can't help with that, don't know what hashed str is – Minsky Nov 13 '20 at 01:09

1 Answers1

0

Did you hash the password when the user is saved on registration? You can check whether the password is plaintext.