Initial push of Plunk Next

This commit is contained in:
Dries Augustyns
2025-12-01 09:56:56 +01:00
parent 07cea20262
commit ff1876d580
566 changed files with 89036 additions and 28423 deletions
+37
View File
@@ -0,0 +1,37 @@
import bcrypt from 'bcrypt';
import {UserService} from './UserService.js';
export class AuthService {
public static async generateHash(password: string): Promise<string> {
return new Promise((resolve, reject) => {
void bcrypt.hash(password, 10, (err, res) => {
if (err) {
return reject(err);
}
resolve(res);
});
});
}
public static async verifyHash(password: string, hash: string) {
return new Promise((resolve, reject) => {
void bcrypt.compare(password, hash, (err, res) => {
if (err) {
return reject(err);
}
return resolve(res);
});
});
}
public static async verifyCredentials(email: string, password: string) {
const user = await UserService.email(email);
if (!user?.password) {
return false;
}
return await this.verifyHash(password, user.password);
}
}