backend: Integrate bcrypt for password hashing and verification

This commit is contained in:
juancarmore 2025-03-26 12:40:30 +01:00
parent d10e6ea519
commit 6725330a7a
4 changed files with 374 additions and 15 deletions

File diff suppressed because it is too large Load Diff

View File

@ -42,6 +42,7 @@
},
"dependencies": {
"@aws-sdk/client-s3": "3.673.0",
"bcrypt": "5.1.1",
"chalk": "5.4.1",
"cookie-parser": "1.4.7",
"cors": "2.8.5",
@ -62,6 +63,7 @@
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "^2.16.3",
"@types/bcrypt": "5.0.2",
"@types/cookie-parser": "1.4.7",
"@types/cors": "2.8.17",
"@types/express": "4.17.21",

View File

@ -0,0 +1,13 @@
import bcrypt from 'bcrypt';
const SALT_ROUNDS = 10;
export class PasswordHelper {
static async hashPassword(password: string): Promise<string> {
return bcrypt.hash(password, SALT_ROUNDS);
}
static async verifyPassword(password: string, hash: string): Promise<boolean> {
return bcrypt.compare(password, hash);
}
}

View File

@ -10,6 +10,7 @@ import { GlobalPreferencesStorageFactory } from './global-preferences.factory.js
import { errorRoomNotFound, OpenViduMeetError } from '../../models/error.model.js';
import { MEET_NAME_ID, MEET_SECRET, MEET_USER, MEET_WEBHOOK_ENABLED, MEET_WEBHOOK_URL } from '../../environment.js';
import { injectable, inject } from '../../config/dependency-injector.config.js';
import { PasswordHelper } from '../../helpers/password.helper.js';
@injectable()
export class GlobalPreferencesService<
@ -29,7 +30,7 @@ export class GlobalPreferencesService<
* @returns {Promise<G>} Default global preferences.
*/
async ensurePreferencesInitialized(): Promise<G> {
const preferences = this.getDefaultPreferences();
const preferences = await this.getDefaultPreferences();
try {
await this.storage.initialize(preferences);
@ -135,7 +136,7 @@ export class GlobalPreferencesService<
* Returns the default global preferences.
* @returns {G}
*/
protected getDefaultPreferences(): G {
protected async getDefaultPreferences(): Promise<G> {
return {
projectId: MEET_NAME_ID,
webhooksPreferences: {
@ -153,7 +154,7 @@ export class GlobalPreferencesService<
type: AuthType.SINGLE_USER,
credentials: {
username: MEET_USER,
passwordHash: MEET_SECRET
passwordHash: await PasswordHelper.hashPassword(MEET_SECRET)
}
}
}