first commit
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 1m4s
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 1m4s
This commit is contained in:
commit
6fc0a01c56
51 changed files with 11319 additions and 0 deletions
25
server/auth.js
Normal file
25
server/auth.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import {
|
||||
scryptSync,
|
||||
randomBytes,
|
||||
timingSafeEqual,
|
||||
createHash,
|
||||
} from "node:crypto";
|
||||
export function hashPassword(password) {
|
||||
const salt = randomBytes(16).toString("hex");
|
||||
return `scrypt:${salt}:${scryptSync(password, salt, 64).toString("hex")}`;
|
||||
}
|
||||
export function checkPassword(password, hash) {
|
||||
const [method, salt, hex] = hash.split(":");
|
||||
if (
|
||||
method !== "scrypt" ||
|
||||
!/^[a-f0-9]{32}$/.test(salt) ||
|
||||
!/^[a-f0-9]{128}$/.test(hex)
|
||||
)
|
||||
return false;
|
||||
return timingSafeEqual(
|
||||
scryptSync(password, salt, 64),
|
||||
Buffer.from(hex, "hex"),
|
||||
);
|
||||
}
|
||||
export const tokenHash = (token) =>
|
||||
createHash("sha256").update(token).digest("hex");
|
||||
Loading…
Add table
Add a link
Reference in a new issue