Created
May 24, 2022 00:40
-
-
Save riipandi/595cb3a82f54f48b0de6fab0f1f4237a to your computer and use it in GitHub Desktop.
Hash in Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bcrypt from '@node-rs/bcrypt'; | |
export async function hashPassword(str: string): Promise<string> { | |
return await bcrypt.hash(str, 10); | |
} | |
export async function validatePassword(str: string, hash: string): Promise<boolean> { | |
return bcrypt.verify(str, hash); | |
} | |
export function hashPasswordSync(str: string): string { | |
return bcrypt.hashSync(str, 10); | |
} | |
export function validatePasswordSync(str: string, hash: string): boolean { | |
return bcrypt.verifySync(str, hash); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment