All files / src/utils encryption.ts

100% Statements 16/16
100% Branches 1/1
100% Functions 5/5
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 183x 3x   11x 11x 11x 11x     3x 1x 1x 1x     4x 2x  
import * as bcrypt from 'bcryptjs';
import { createHash } from 'crypto';
 
export const bcryptPassword = async (password: string): Promise<string> => {
  const salt = await bcrypt.genSalt(10);
  const hash = await bcrypt.hash(password, salt);
  return hash;
};
 
export const hashPassword = (password: string, algorithm: string) => {
  const hash = createHash(algorithm);
  hash.update(password);
  return hash.digest('hex');
};
 
export const verifyPassword = async (password: string, hash: string): Promise<boolean> =>
  bcrypt.compare(password, hash);