checking for same password on changing

This commit is contained in:
slawk0
2024-09-08 13:43:44 +02:00
parent d3be5952dc
commit a8a2211dae
3 changed files with 8 additions and 4 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
node_modules/ node_modules/
.idea .idea
package-lock.json package-lock.json
.env

View File

@@ -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: {

View File

@@ -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);