From d23be741c958c8978dd9818cb0f0d89f15dcd6b4 Mon Sep 17 00:00:00 2001 From: tetuaoro <65575727+tetuaoro@users.noreply.github.com> Date: Fri, 2 Aug 2024 16:32:11 +0200 Subject: [PATCH] update: add docs - README: init password - add docs support to database interface --- README.md | 6 ++++++ src/lib/database/AbstractDatabase.js | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/README.md b/README.md index be8a32cb..f21c398b 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,12 @@ execute `docker compose up --detach`. Are you enjoying this project? [Buy Emile a beer!](https://github.com/sponsors/WeeJeWel) 🍻 +## Password initialization + +When the application initializes the database for the first time, it sets up an admin user with a default password : `admin`. You have the option to set your own password instead using either the `PASSWORD` environment variable or the `PASSWORD_HASH` environment variable. Follow [this link](./How_to_generate_an_bcrypt_hash.md) to generate a bcrypt hash password. + +The `PASSWORD` environment variable is plain text and will be hashed at runtime by wg-easy. On the other hand, the `PASSWORD_HASH` environment variable is already hashed. + ## Options These options can be configured by setting environment variables using `-e KEY="VALUE"` in the `docker run` command. diff --git a/src/lib/database/AbstractDatabase.js b/src/lib/database/AbstractDatabase.js index 2f16b4f3..aaa1bb11 100644 --- a/src/lib/database/AbstractDatabase.js +++ b/src/lib/database/AbstractDatabase.js @@ -10,14 +10,37 @@ module.exports = class DatabaseInterface { } } + /** + * Initializes the database if does not exist + * + * @returns {Promise} + * @throws {ServerError} If not implemented by the subclass + */ async initDb() { throw new ServerError('You must implement this function'); } + /** + * Compares the provided password with the stored password for the given username + * + * @param {string} username - The username of the user + * @param {string} password - The password to compare + * @returns {Promise} - Return `true` if the password matches, otherwise `false` + * @throws {ServerError} If not implemented by the subclass + */ async comparePassword(username, password) { throw new ServerError('You must implement this function'); } + /** + * Updates the password for the given user + * + * @param {string} username - The username of the user + * @param {string} oldPassword - The current password of the user + * @param {string} newPassword - The new password to set + * @returns {Promise} + * @throws {ServerError} If not implemented by the subclass + */ async updatePassword(username, oldPassword, newPassword) { throw new ServerError('You must implement this function'); }