17 lines
372 B
TypeScript
17 lines
372 B
TypeScript
|
|
import * as bcrypt from 'bcrypt';
|
||
|
|
|
||
|
|
const SALT_ROUNDS = 10;
|
||
|
|
|
||
|
|
/** bcrypt 加密明文密码 */
|
||
|
|
export async function hashPassword(plain: string): Promise<string> {
|
||
|
|
return bcrypt.hash(plain, SALT_ROUNDS);
|
||
|
|
}
|
||
|
|
|
||
|
|
/** bcrypt 校验密码 */
|
||
|
|
export async function comparePassword(
|
||
|
|
plain: string,
|
||
|
|
hashed: string,
|
||
|
|
): Promise<boolean> {
|
||
|
|
return bcrypt.compare(plain, hashed);
|
||
|
|
}
|