2017-07-19 10:21:52 +02:00
|
|
|
let bcrypt;
|
|
|
|
try {
|
2018-03-30 15:30:30 -04:00
|
|
|
bcrypt = require('bcrypt');
|
2017-07-19 10:21:52 +02:00
|
|
|
} catch (err) {
|
2018-03-30 15:30:30 -04:00
|
|
|
bcrypt = require('bcryptjs');
|
2017-07-19 10:21:52 +02:00
|
|
|
}
|
2017-07-09 22:36:25 +02:00
|
|
|
|
|
|
|
export class PasswordHelper {
|
2017-07-11 09:01:59 +02:00
|
|
|
public static cryptPassword(password) {
|
2017-07-19 10:21:52 +02:00
|
|
|
const salt = bcrypt.genSaltSync(9);
|
|
|
|
return bcrypt.hashSync(password, salt);
|
2017-07-09 22:36:25 +02:00
|
|
|
}
|
|
|
|
|
2017-07-11 09:01:59 +02:00
|
|
|
public static comparePassword(password, encryptedPassword) {
|
2017-07-19 10:21:52 +02:00
|
|
|
return bcrypt.compareSync(password, encryptedPassword);
|
2017-07-09 22:36:25 +02:00
|
|
|
}
|
|
|
|
}
|