password.service.ts 375 B

123456789101112131415
  1. import { Injectable } from '@nestjs/common';
  2. import * as bcrypt from 'bcrypt';
  3. const SALT_ROUNDS = 12;
  4. @Injectable()
  5. export class PasswordService {
  6. hash(plaintext: string): Promise<string> {
  7. return bcrypt.hash(plaintext, SALT_ROUNDS);
  8. }
  9. check(plaintext: string, hash: string): Promise<boolean> {
  10. return bcrypt.compare(plaintext, hash);
  11. }
  12. }