From 208cd615af8250686745aa5b6779706ae267e423 Mon Sep 17 00:00:00 2001 From: Cowch Date: Sat, 22 Mar 2025 10:04:14 -0500 Subject: [PATCH] refactor(auth): added in correct bycrptjs --- server/services/auth/utils/checkPassword.ts | 28 +++++++++++--------- server/services/auth/utils/createPassword.ts | 22 +++++++-------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/server/services/auth/utils/checkPassword.ts b/server/services/auth/utils/checkPassword.ts index 2866852..a0e861b 100644 --- a/server/services/auth/utils/checkPassword.ts +++ b/server/services/auth/utils/checkPassword.ts @@ -1,16 +1,18 @@ -import bcrypt from "bcrypt"; +import bcrypt from "bcryptjs"; +export const checkPassword = async ( + currentPassword: string, + dbPassword: string +) => { + let decyptPass = ""; + try { + decyptPass = atob(dbPassword); + } catch (error) { + console.log(error); + } + // encypt password + const pass: string | undefined = process.env.SECRET; -export const checkPassword = async (currentPassword: string, dbPassword: string) => { - let decyptPass = ""; - try { - decyptPass = atob(dbPassword); - } catch (error) { - console.log(error); - } - // encypt password - const pass: string | undefined = process.env.SECRET; + const checked = bcrypt.compareSync(pass + currentPassword, decyptPass); - const checked = bcrypt.compareSync(pass + currentPassword, decyptPass); - - return checked; + return checked; }; diff --git a/server/services/auth/utils/createPassword.ts b/server/services/auth/utils/createPassword.ts index 1a0aa9f..9cf5950 100644 --- a/server/services/auth/utils/createPassword.ts +++ b/server/services/auth/utils/createPassword.ts @@ -1,17 +1,17 @@ -import bcrypt from "bcrypt"; +import bcrypt from "bcryptjs"; export const createPassword = async (password: string) => { - // encypt password - let pass: string | undefined = process.env.SECRET; - let salt: string | undefined = process.env.SALTING; + // encypt password + let pass: string | undefined = process.env.SECRET; + let salt: string | undefined = process.env.SALTING; - if (!pass || !salt) { - pass = "error"; - } else { - pass = bcrypt.hashSync(pass + password, parseInt(salt)); + if (!pass || !salt) { + pass = "error"; + } else { + pass = bcrypt.hashSync(pass + password, parseInt(salt)); - pass = btoa(pass); - } + pass = btoa(pass); + } - return pass; + return pass; };