feat(authentication): create credentials service

A new credentials service has been created with two main functionalities: hashing a password and comparing an original password with a hash. These methods use the Argon2id hashing function and are intended to be part of the authentication process.
This commit is contained in:
Mathis H (Avnyr) 2024-05-21 14:02:21 +02:00
parent 8d7d8d750d
commit 18c20c52d5
Signed by: Mathis
GPG Key ID: DD9E0666A747D126

View File

@ -0,0 +1,24 @@
import Argon2id from "@node-rs/argon2";
//ToTest
export async function getHashFromPassword(password: string) {
return await Argon2id.hash(password, {
secret: Buffer.from(`${process.env["HASH_SECRET"]}`),
algorithm: 2,
});
}
//ToTest
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;