checking for same password on changing
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
node_modules/
|
||||
.idea
|
||||
package-lock.json
|
||||
package-lock.json
|
||||
.env
|
||||
@@ -27,6 +27,8 @@ document.getElementById('signupForm').addEventListener('submit',async function (
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const response = await fetch ('/auth/signup', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
||||
7
index.js
7
index.js
@@ -73,8 +73,9 @@ app.post('/auth/changepassword', async (req, res) => {
|
||||
if(!cPassword && nPassword) {
|
||||
return res.json({ message: 'Field is empty' })
|
||||
}
|
||||
|
||||
console.log(cPassword, nPassword)
|
||||
if(nPassword === cPassword) {
|
||||
return res.json({ message: 'Passwords are the same' })
|
||||
}
|
||||
let username;
|
||||
try {
|
||||
const decoded = jwt.verify(token, jwtSecret);
|
||||
@@ -88,7 +89,7 @@ app.post('/auth/changepassword', async (req, res) => {
|
||||
const match = await bcrypt.compare(cPassword, result.rows[0].password);
|
||||
// if not return information
|
||||
if(!match){
|
||||
return res.json({ message: 'Current password is not valid', success: false })
|
||||
return res.json({ message: 'Current password is invalid', success: false })
|
||||
}
|
||||
// hash password
|
||||
const salt = await bcrypt.genSalt(saltRounds);
|
||||
|
||||
Reference in New Issue
Block a user