fix: lint errors
This commit is contained in:
parent
a9c798deda
commit
f5d93f6c5a
13
src/wgpw.mjs
13
src/wgpw.mjs
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
// Import needed libraries
|
||||
import bcrypt from 'bcryptjs';
|
||||
|
||||
|
@ -6,25 +8,28 @@ 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 {
|
||||
|
@ -40,10 +45,10 @@ const comparePassword = async (password, hash) => {
|
|||
} else if (password) {
|
||||
await generateHash(password);
|
||||
}
|
||||
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(error);
|
||||
// eslint-disable-next-line no-process-exit
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
||||
|
|
Loading…
Reference in New Issue