| Total Complexity | 4 |
| Complexity/F | 1 |
| Lines of Code | 25 |
| Function Count | 4 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 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 |