refactor(auth): added in correct bycrptjs
This commit is contained in:
@@ -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) => {
|
const checked = bcrypt.compareSync(pass + currentPassword, decyptPass);
|
||||||
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);
|
return checked;
|
||||||
|
|
||||||
return checked;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
import bcrypt from "bcrypt";
|
import bcrypt from "bcryptjs";
|
||||||
|
|
||||||
export const createPassword = async (password: string) => {
|
export const createPassword = async (password: string) => {
|
||||||
// encypt password
|
// encypt password
|
||||||
let pass: string | undefined = process.env.SECRET;
|
let pass: string | undefined = process.env.SECRET;
|
||||||
let salt: string | undefined = process.env.SALTING;
|
let salt: string | undefined = process.env.SALTING;
|
||||||
|
|
||||||
if (!pass || !salt) {
|
if (!pass || !salt) {
|
||||||
pass = "error";
|
pass = "error";
|
||||||
} else {
|
} else {
|
||||||
pass = bcrypt.hashSync(pass + password, parseInt(salt));
|
pass = bcrypt.hashSync(pass + password, parseInt(salt));
|
||||||
|
|
||||||
pass = btoa(pass);
|
pass = btoa(pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pass;
|
return pass;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user