Build starter.

This commit is contained in:
Pierre THIERRY
2020-09-05 13:01:05 +02:00
committed by takiguchi
parent e794e65942
commit 94226c140e
22 changed files with 987 additions and 100 deletions

View File

@@ -0,0 +1,27 @@
const bcrypt = require('bcrypt');
const saltRounds = 10;
class PasswordService {
/**
* Hashes the password in parameters.
* @param {String} password The plain text password.
* @returns The hashed password.
*/
hashPassword(password) {
const salt = bcrypt.genSaltSync(saltRounds);
return bcrypt.hashSync(password, salt);
}
/**
* Checks if the {@code plainTextPassword} matches the hashed password.
* @param {String} plainTextPassword The plain text password.
* @param {String} hashedPassword The hashed password.
* @returns A boolean.
*/
areSamePasswords(plainTextPassword, hashedPassword) {
return bcrypt.compareSync(plainTextPassword, hashedPassword);
}
}
const singleton = new PasswordService();
module.exports = singleton;