MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / verifyPassword

Function verifyPassword

packages/common/server/crypto.ts:38–60  ·  view source on GitHub ↗
(
  password: string,
  hash: string,
  keyLength = 32,
)

Source from the content-addressed store, hash-verified

36 * @returns {boolean}
37 */
38export async function verifyPassword(
39 password: string,
40 hash: string,
41 keyLength = 32,
42): Promise<boolean> {
43 return new Promise((resolve, reject) => {
44 const [salt, hashKey] = hash.split('.');
45 // we need to pass buffer values to timingSafeEqual
46 const hashKeyBuff = Buffer.from(hashKey!, 'hex');
47 scrypt(password, salt!, keyLength, (err, derivedKey) => {
48 if (err) {
49 reject(err);
50 }
51 // compare the new supplied password with the hashed password using timeSafeEqual
52 resolve(
53 timingSafeEqual(
54 new Uint8Array(hashKeyBuff),
55 new Uint8Array(derivedKey),
56 ),
57 );
58 });
59 });
60}
61
62export function createHash(data: string, len: number) {
63 return cryptoCreateHash('shake256', { outputLength: len })

Callers 5

authenticateTokenFunction · 0.90
validateSdkRequestFunction · 0.90
validateExportRequestFunction · 0.90
validateImportRequestFunction · 0.90
validateManageRequestFunction · 0.90

Calls 1

fromMethod · 0.45

Tested by

no test coverage detected