diff --git a/interfaces/final-object.interface.ts b/interfaces/final-object.interface.ts index 97811617..822099a3 100644 --- a/interfaces/final-object.interface.ts +++ b/interfaces/final-object.interface.ts @@ -24,6 +24,7 @@ export interface FinalObject { removeTags: string[]; // tags to remove screenshotSettings: ScreenshotSettings; version: number; // version of this vha file + password?: string; // Optional password field } export interface ImageElement { @@ -103,3 +104,20 @@ export interface ScreenshotSettings { height: AllowedScreenshotHeight; n: number; } + +//Setting the password +import bcrypt from 'bcrypt'; + +const saltRounds = 10; + +async function setPassword(finalObject: FinalObject, plainPassword: string) { + const hashedPassword = await bcrypt.hash(plainPassword, saltRounds); + finalObject.password = hashedPassword; // Store the hashed password +} + +// Verifying the password +async function verifyPassword(finalObject: FinalObject, inputPassword: string) { + if (!finalObject.password) return false; // No password set + const match = await bcrypt.compare(inputPassword, finalObject.password); + return match; // Returns true if the password matches +}