23 lines
539 B
TypeScript
23 lines
539 B
TypeScript
import Argon2id from "@node-rs/argon2";
|
|
|
|
|
|
export async function getHashFromPassword(password: string) {
|
|
return await Argon2id.hash(password,{
|
|
secret: Buffer.from(`${process.env["HASH_SECRET"]}`),
|
|
algorithm: 2
|
|
})
|
|
}
|
|
|
|
export async function comparePassword(password: string, hash: string) {
|
|
return await Argon2id.verify(hash, password, {
|
|
secret: Buffer.from(`${process.env["HASH_SECRET"]}`),
|
|
algorithm: 2
|
|
});
|
|
}
|
|
|
|
const CredentialService = {
|
|
compare: comparePassword,
|
|
hash: getHashFromPassword,
|
|
}
|
|
|
|
export default CredentialService; |