fix: change tpin match with hashing and not directly
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user