Password Hashing
The Password Hashing component provides secure, battle-tested utilities for hashing and verifying user passwords.
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
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.