Created
July 15, 2025 17:38
-
-
Save gameshler/9f3607e31c80ce020eba8c9d1973426e to your computer and use it in GitHub Desktop.
Reusable functions to hash and compare sensitive values using bcryptjs in TypeScript. Defaults to 12 salt rounds. Gracefully handles comparison errors. Ideal for a secure user authentication.
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 "bcryptjs"; | |
| export const hashValue = async (value: string, saltRounds?: number) => | |
| bcrypt.hash(value, saltRounds || 12); | |
| export const compareValue = async (value: string, hashedValue: string) => | |
| bcrypt.compare(value, hashedValue).catch(() => false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment