Passed
Push — master ( e6aee2...1ab6c1 )
by Leandro
01:23
created

src/utils/hash.ts   A

Complexity

Total Complexity 4
Complexity/F 1

Size

Lines of Code 25
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 20
mnd 0
bc 0
fnc 4
dl 0
loc 25
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A hash.ts ➔ randomString 0 6 1
A hash.ts ➔ randomInt 0 3 1
A hash.ts ➔ comparePassword 0 3 1
A hash.ts ➔ generateHash 0 3 1
1
import { hash, compare} from "bcrypt";
2
import { uid } from "rand-token";
3
import crypto from "crypto";
4
5
const HASH_SALT_ROUNDS = 12;
6
7
export function generateHash(plain: string) : Promise<string> {
8
  return hash(plain, HASH_SALT_ROUNDS);
9
}
10
11
export function comparePassword(plain: string, encrypted: string) : Promise<boolean> {
12
  return compare(plain, encrypted);
13
}
14
15
export function randomString(size: number = 21): string {
16
  return crypto
17
    .randomBytes(size)
18
    .toString('base64')
19
    .slice(0, size);
20
}
21
22
export function randomInt(size: number = 5) {
23
  return uid(size, "0123456789");
24
}
25