Build MerchantFlow onboarding CRM foundation
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import { scryptSync, randomBytes, timingSafeEqual } from 'node:crypto';
|
||||
export function hashPassword(password: string) {
|
||||
const salt = randomBytes(16).toString('hex');
|
||||
return `${salt}:${scryptSync(password, salt, 64).toString('hex')}`;
|
||||
}
|
||||
export function verifyPassword(password: string, stored: string) {
|
||||
const [salt, hash] = stored.split(':');
|
||||
if (!salt || !hash) return false;
|
||||
const expected = Buffer.from(hash, 'hex');
|
||||
const actual = scryptSync(password, salt, 64);
|
||||
return expected.length === actual.length && timingSafeEqual(actual, expected);
|
||||
}
|
||||
Reference in New Issue
Block a user