mirror of https://github.com/wg-easy/wg-easy
22 changed files with 88 additions and 144 deletions
@ -1,11 +0,0 @@ |
|||
{ |
|||
"[javascript]": { |
|||
"editor.formatOnSave": true, |
|||
"editor.formatOnType": true |
|||
}, |
|||
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces": false, |
|||
"javascript.format.semicolons": "insert", |
|||
"editor.tabSize": 2, |
|||
"editor.indentSize": "tabSize", |
|||
"editor.detectIndentation": false |
|||
} |
|||
@ -1,28 +0,0 @@ |
|||
# wg-password |
|||
|
|||
`wg-password` (wgpw) is a script that generates bcrypt password hashes for use with `wg-easy`, enhancing security by requiring passwords. |
|||
|
|||
## Features |
|||
|
|||
- Generate bcrypt password hashes. |
|||
- Easily integrate with `wg-easy` to enforce password requirements. |
|||
|
|||
## Usage with Docker |
|||
|
|||
To generate a bcrypt password hash using docker, run the following command : |
|||
|
|||
```sh |
|||
docker run ghcr.io/wg-easy/wg-easy wgpw YOUR_PASSWORD |
|||
PASSWORD_HASH='$2b$12$coPqCsPtcFO.Ab99xylBNOW4.Iu7OOA2/ZIboHN6/oyxca3MWo7fW' // literally YOUR_PASSWORD |
|||
``` |
|||
|
|||
*Important* : make sure to enclose your password in single quotes when you run `docker run` command : |
|||
|
|||
```bash |
|||
$ echo $2b$12$coPqCsPtcF |
|||
b2 |
|||
$ echo "$2b$12$coPqCsPtcF" |
|||
b2 |
|||
$ echo '$2b$12$coPqCsPtcF' |
|||
$2b$12$coPqCsPtcF |
|||
``` |
|||
@ -1,54 +0,0 @@ |
|||
'use strict'; |
|||
|
|||
// Import needed libraries
|
|||
import bcrypt from 'bcryptjs'; |
|||
|
|||
// Function to generate hash
|
|||
const generateHash = async (password) => { |
|||
try { |
|||
const salt = await bcrypt.genSalt(12); |
|||
const hash = await bcrypt.hash(password, salt); |
|||
// eslint-disable-next-line no-console
|
|||
console.log(`PASSWORD_HASH='${hash}'`); |
|||
} catch (error) { |
|||
throw new Error(`Failed to generate hash : ${error}`); |
|||
} |
|||
}; |
|||
|
|||
// Function to compare password with hash
|
|||
const comparePassword = async (password, hash) => { |
|||
try { |
|||
const match = await bcrypt.compare(password, hash); |
|||
if (match) { |
|||
// eslint-disable-next-line no-console
|
|||
console.log('Password matches the hash !'); |
|||
} else { |
|||
// eslint-disable-next-line no-console
|
|||
console.log('Password does not match the hash.'); |
|||
} |
|||
} catch (error) { |
|||
throw new Error(`Failed to compare password and hash : ${error}`); |
|||
} |
|||
}; |
|||
|
|||
(async () => { |
|||
try { |
|||
// Retrieve command line arguments
|
|||
const args = process.argv.slice(2); // Ignore the first two arguments
|
|||
if (args.length > 2) { |
|||
throw new Error('Usage : wgpw YOUR_PASSWORD [HASH]'); |
|||
} |
|||
|
|||
const [password, hash] = args; |
|||
if (password && hash) { |
|||
await comparePassword(password, hash); |
|||
} else if (password) { |
|||
await generateHash(password); |
|||
} |
|||
} catch (error) { |
|||
// eslint-disable-next-line no-console
|
|||
console.error(error); |
|||
// eslint-disable-next-line no-process-exit
|
|||
process.exit(1); |
|||
} |
|||
})(); |
|||
@ -1,5 +0,0 @@ |
|||
#!/bin/sh |
|||
# This script is intended to be run only inside a docker container, not on the development host machine |
|||
set -e |
|||
# proxy command |
|||
node /app/wgpw.mjs "$@" |
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue