feat: initial commit
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { argon2id, argon2Verify } from "hash-wasm";
|
||||
|
||||
export async function validatePassword(
|
||||
password: string,
|
||||
hash: string
|
||||
): Promise<boolean> {
|
||||
return await argon2Verify({ password, hash });
|
||||
}
|
||||
|
||||
export async function hashPassword(
|
||||
password: string
|
||||
): Promise<`$${string}$${string}`> {
|
||||
const salt = new Uint8Array(16);
|
||||
crypto.getRandomValues(salt);
|
||||
const hash = await argon2id({
|
||||
password,
|
||||
outputType: "encoded",
|
||||
hashLength: 32,
|
||||
iterations: 3,
|
||||
memorySize: 65536,
|
||||
parallelism: 4,
|
||||
salt,
|
||||
});
|
||||
return hash as `$${string}$${string}`;
|
||||
}
|
||||
Reference in New Issue
Block a user