Files
ExpressJS-Mongo/src/js/service/passwordService.js
Pierre THIERRY 94226c140e Build starter.
2020-09-27 09:11:13 +02:00

27 lines
820 B
JavaScript

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;