Password Hashing
The Password Hashing component provides secure, battle-tested utilities for hashing and verifying user passwords.
It supports multiple algorithms so you can choose the right trade-off between security, performance, and compatibility.
Supported algorithms:
- argon2 (recommended)
- bcryptjs
- scrypt
- pbkdf2
Installation Guide
Install the component using the Servercn CLI:
npx servercn-cli add password-hashingYou will be prompted to select a password hashing strategy:
The CLI will then automatically configure the component based on your selected strategy.
Basic Implementation
You can place the following helpers in your project:
MVC: src/helpers/auth.helpers.ts
Feature: src/modules/auth/auth.helpers.ts
Choose one password hashing strategy based on your security and performance requirements.
1. argon2 ✅
A modern, memory-hard algorithm designed to resist GPU and ASIC attacks. Best choice for new applications
2. bcryptjs
A widely adopted and battle-tested algorithm with configurable cost factor. Suitable for legacy compatibility.
3. scrypt
A memory-intensive algorithm that significantly increases the cost of brute-force attacks.
4. pbkdf2
A standards-based algorithm included in Node.js core. Useful when external dependencies are not allowed.
Recommendation
For most applications:
- Use Argon2 for new projects
- Use bcrypt only for compatibility with existing systems
- Prefer scrypt or PBKDF2 when external dependencies are restricted