typescriptbeginner
Bcrypt Password Hash & Verify
Hash and verify passwords with bcrypt using configurable salt rounds and timing-safe comparison.
typescriptPress ⌘/Ctrl + Shift + C to copy
import bcrypt from 'bcrypt';
const SALT_ROUNDS = 12;
export async function hashPassword(plain: string): Promise<string> {
return bcrypt.hash(plain, SALT_ROUNDS);
}
export async function verifyPassword(
plain: string,
hashed: string
): Promise<boolean> {
return bcrypt.compare(plain, hashed);
}
// Usage
// const hash = await hashPassword('my-secure-password');
// const isValid = await verifyPassword('my-secure-password', hash);Use Cases
- User registration
- Login authentication
- Password reset
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
typescriptintermediate
Node.js Crypto Utility Functions
Common cryptographic operations: hashing, HMAC, encryption, random tokens, and password hashing.
Best for: Secure password storage and verification
#nodejs#crypto
javaintermediate
Secure Password Hashing
Hash passwords securely with PBKDF2 and verify them — no external libraries required.
Best for: User registration password storage
#java#security
typescriptintermediate
In-Memory Rate Limiter for Express
Token bucket rate limiter middleware for Express with configurable window and max requests per IP.
Best for: API abuse prevention
#express#rate-limit
typescriptadvanced
JWT Refresh Token Rotation
Implement secure token rotation with short-lived access tokens and one-time-use refresh tokens.
Best for: Secure API authentication
#jwt#authentication