chore:little fixes and formating and linting and patches

This commit is contained in:
2026-03-31 15:50:54 +02:00
parent a1ce71ffb6
commit 9b197abcfa
815 changed files with 22960 additions and 8982 deletions

View File

@@ -16,13 +16,15 @@ export function generateSalt() {
*/
export async function hashPassword(
password: string,
keyLength = 32,
keyLength = 32
): Promise<string> {
return new Promise((resolve, reject) => {
// generate random 16 bytes long salt - recommended by NodeJS Docs
const salt = generateSalt();
scrypt(password, salt, keyLength, (err, derivedKey) => {
if (err) reject(err);
if (err) {
reject(err);
}
// derivedKey is of type Buffer
resolve(`${salt}.${derivedKey.toString('hex')}`);
});
@@ -38,7 +40,7 @@ export async function hashPassword(
export async function verifyPassword(
password: string,
hash: string,
keyLength = 32,
keyLength = 32
): Promise<boolean> {
return new Promise((resolve, reject) => {
const [salt, hashKey] = hash.split('.');
@@ -50,10 +52,7 @@ export async function verifyPassword(
}
// compare the new supplied password with the hashed password using timeSafeEqual
resolve(
timingSafeEqual(
new Uint8Array(hashKeyBuff),
new Uint8Array(derivedKey),
),
timingSafeEqual(new Uint8Array(hashKeyBuff), new Uint8Array(derivedKey))
);
});
});