Skip to content

Instantly share code, notes, and snippets.

@riipandi
Created May 24, 2022 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riipandi/595cb3a82f54f48b0de6fab0f1f4237a to your computer and use it in GitHub Desktop.
Save riipandi/595cb3a82f54f48b0de6fab0f1f4237a to your computer and use it in GitHub Desktop.
Hash in Node.js
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