I am unable to get bcrypt working in react.
Steps:
npm install bcryptjs
const bcrypt = require(“bcryptjs”);
const signupinfo = {
firstName: fname,
lastName: lname,
email: email,
pwd: bcrypt.hashSync(password),
};
//this is then saved to Postgres via spring rest api
I have another form that pulls the DB records and passes to “react”, which then compares.
const isPasswordValid = bcrypt.compareSync(password,
response.data.pwd);
This is not working as expected. It was returning false, yesterday and today it was always true, even for incorect password.
Scenario:
Signup form …hash and store
Login form …retrieve and compare with plain password in the form.
Test cases:
- In Login form enter correct password and submit. check console is printing true or not
- In the same Login page,edit password with extra character. expecting console to print false.
But the test are not working as expected. Not sure if there is any cache etc.
The link
https://www.npmjs.com/package/bcryptjs-react tells npm i bcryptjs-react and also npm install bcryptjs
Not sure if both need to be installed.
All I see everywhere is simple 3 lines of usage code, but does not work
like many posts – post1 , post2
What is the mistake? please advice