forked from mirrors/amnezia-wg-easy
move files
This commit is contained in:
parent
781d56d0ff
commit
a9c798deda
6 changed files with 2 additions and 52 deletions
49
src/wgpw.mjs
Normal file
49
src/wgpw.mjs
Normal file
|
@ -0,0 +1,49 @@
|
|||
// 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);
|
||||
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) {
|
||||
console.log('Password matches the hash !');
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
5
src/wgpw.sh
Executable file
5
src/wgpw.sh
Executable file
|
@ -0,0 +1,5 @@
|
|||
#!/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 "$@"
|
Loading…
Add table
Add a link
Reference in a new issue