Build starter.
This commit is contained in:
27
src/js/service/passwordService.js
Normal file
27
src/js/service/passwordService.js
Normal 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;
|
||||
Reference in New Issue
Block a user