fix: change tpin match with hashing and not directly

This commit is contained in:
2025-11-08 20:28:21 +05:30
parent b9c9d35f74
commit f922179765

View File

@@ -187,12 +187,12 @@ async function changeTpin(req, res) {
if (!user.tpin)
return res.status(400).json({ error: 'USER_DOESNT_HAVE_A_TPIN' });
const { oldTpin, newTpin } = req.body;
if (oldTpin !== user.tpin)
return res.status(400).json({ error: 'TPIN_DOESNT_MATCH' });
const isMatch = await comparePassword(oldTpin, user.tpin);
if (!isMatch) return res.status(400).json({ error: 'TPIN_DOESNT_MATCH' });
if (!/^\d{6}$/.test(newTpin))
return res.status(400).json({ error: 'INVALID_TPIN_FORMAT' });
authService.setTpin(customerNo, tpin);
await authService.setTpin(customerNo, newTpin);
return res.json({ message: 'TPIN_SET' });
} catch (error) {
logger.error(error);