CI / install-and-build (pull_request) Successful in 1m29s
CI / format (pull_request) Successful in 51s
CI / typecheck-source (pull_request) Successful in 41s
CI / typecheck-tests (pull_request) Successful in 39s
CI / test (pull_request) Successful in 51s
CI / lint (pull_request) Successful in 21s
Co-Authored-By: gpt-5.6-terra <noreply@openai.com>
26 lines
577 B
TypeScript
26 lines
577 B
TypeScript
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}`;
|
|
}
|