From 3e581b689e362a714b6db5eca6cc503f307c32d2 Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 14 Feb 2022 00:22:25 +0000 Subject: [PATCH] Implemented PasswordReset hashToken --- lib/PasswordReset.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/PasswordReset.js b/lib/PasswordReset.js index 04e73eb..5f13aca 100644 --- a/lib/PasswordReset.js +++ b/lib/PasswordReset.js @@ -1,5 +1,8 @@ 'use strict'; +const bcrypt = require('bcrypt'); +const crypto = require('crypto'); + const DatabaseConnectionPool = require('./DatabaseConnectionPool'); class PasswordReset { @@ -35,8 +38,16 @@ class PasswordReset { } - static hashToken(password) { + static async hashToken(u) { + const nonce = crypto + .randomBytes(16) + .toString('hex') + .slice(0, 16); + const tokenString = u.id + u.email + nonce + u.lastName; + const token = await bcrypt.hash(tokenString, 10); + + return [ nonce, token ]; } static generatePasswordReset() {