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