Files
euchre_camp/hash-password.mjs
david 123df671f5 nextjs-rewrite (#5)
Reviewed-on: #5
Co-authored-by: David Gwilliam <dhgwilliam@gmail.com>
Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
2026-03-30 02:30:13 +00:00

17 lines
544 B
JavaScript

import { scrypt } from "@noble/hashes/scrypt";
import { hex } from "@better-auth/utils/hex";
const config = { N: 16384, r: 16, p: 1, dkLen: 64 };
function hashPassword(password) {
const salt = hex.encode(crypto.getRandomValues(new Uint8Array(16)));
const key = scrypt(password.normalize("NFKC"), salt, {
N: config.N, p: config.p, r: config.r, dkLen: config.dkLen,
maxmem: 128 * config.N * config.r * 2
});
return `${salt}:${hex.encode(key)}`;
}
const hashed = hashPassword("admin");
console.log("Hash for 'admin':", hashed);