From 353bb618b445891a09b9978561d8731ff20977d9 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 1 Aug 2021 15:27:23 +0100 Subject: [PATCH] :bug: Normalize data prior to calculatin SHA hash --- src/utils/Auth.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/utils/Auth.js b/src/utils/Auth.js index 57e519f8..a64a7ba4 100644 --- a/src/utils/Auth.js +++ b/src/utils/Auth.js @@ -6,7 +6,11 @@ import { cookieKeys, localStorageKeys } from './defaults'; * @param {String} user The username of user * @returns {String} The hashed token */ -const generateUserToken = (user) => sha256(user.toString()).toString().toLowerCase(); +const generateUserToken = (user) => { + const strAndUpper = (input) => input.toString().toUpperCase(); + const sha = sha256(strAndUpper(user.user) + strAndUpper(user.hash)); + return strAndUpper(sha); +}; /** * Checks if the user is currently authenticated @@ -47,7 +51,7 @@ export const checkCredentials = (username, pass, users) => { response = { correct: false, msg: 'Missing Password' }; } else { users.forEach((user) => { - if (user.user === username) { + if (user.user.toLowerCase() === username.toLowerCase()) { if (user.hash.toLowerCase() === sha256(pass).toString().toLowerCase()) { response = { correct: true, msg: 'Logging in...' }; } else {