2018-11-29 06:49:33 +08:00
|
|
|
let bcrypt: any;
|
2017-07-19 16:21:52 +08:00
|
|
|
try {
|
2018-03-31 03:30:30 +08:00
|
|
|
bcrypt = require('bcrypt');
|
2017-07-19 16:21:52 +08:00
|
|
|
} catch (err) {
|
2018-03-31 03:30:30 +08:00
|
|
|
bcrypt = require('bcryptjs');
|
2017-07-19 16:21:52 +08:00
|
|
|
}
|
2017-07-10 04:36:25 +08:00
|
|
|
|
|
|
|
export class PasswordHelper {
|
2020-01-08 05:17:54 +08:00
|
|
|
public static cryptPassword(password: string): string {
|
2017-07-19 16:21:52 +08:00
|
|
|
const salt = bcrypt.genSaltSync(9);
|
|
|
|
return bcrypt.hashSync(password, salt);
|
2017-07-10 04:36:25 +08:00
|
|
|
}
|
|
|
|
|
2020-01-08 05:17:54 +08:00
|
|
|
public static comparePassword(password: string, encryptedPassword: string): boolean {
|
|
|
|
try {
|
|
|
|
return bcrypt.compareSync(password, encryptedPassword);
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
return false;
|
2017-07-10 04:36:25 +08:00
|
|
|
}
|
|
|
|
}
|