Closed SamiHK closed 6 years ago
I guess the Issue is From database:
-- I have stores password in varchar(50). and minimum lenght required by bcrypt is 60.
let me confirm then I'll close this issue with solution.
Solution : mysql table datatype of password should have a lenght of 60 or greater that 60. And then it works fine.
Nice :-)
Then please close this issue ;-)
this worked for me thanks
Thats my Register User function.
registerUser: function(User, callback) { var saltRounds =10; bcrypt.hash(User.Password, saltRounds, function(err, hash){ if(err){ throw err; } else{ return db.query( "Insert into users (FirstName, LastName, Email, Password, Phone, Pin, Type, ImageUrl, Description) values(?,?,?,?,?,?,?,?,?)", [User.FirstName, User.LastName, User.Email, hash , User.Phone, User.Pin, User.Type,User.ImageUrl, User.Description], callback ); } }); }
And That is Login Function.
loginUser: function(User, callback){ var hash; db.query( "select * from users where Email=?", [User.Email], function(err, results, fields){ if(err) throw err; hash=results[0]["Password"]; bcrypt.compare(User.Password, hash, function(err, res) { if(res){ console.log('true'); return db.query( "select * from users where Email=?&&Password=?", [User.Email, hash], callback ); }else{ console.log('false'); } }); } ); }
I have checked datatypes of both myPassword and hash are string.