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:
parent
8d7d8d750d
commit
18c20c52d5
24
src/services/authentication/credentials.service.ts
Normal file
24
src/services/authentication/credentials.service.ts
Normal 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;
|
Loading…
x
Reference in New Issue
Block a user