Handling passwords: a guide for developers
If you build anything with a login, you’re responsible for some of the most sensitive data your users have. This is a practical summary of current best practice, with links to the detailed standards.
Last reviewed 15 November 2026
Storing passwords
Never store passwords in plain text or with reversible encryption, and never with a fast general-purpose hash such as MD5, SHA-1 or SHA-256 on its own. Use a dedicated, deliberately slow password-hashing function. OWASP’s current minimum parameters:
| Algorithm | Minimum settings | Notes |
|---|---|---|
| Argon2id | m=19456 (19 MiB), t=2, p=1 | First choice |
| scrypt | N=2^17, r=8, p=1 | If Argon2id isn’t available |
| bcrypt | Work factor 10 or more | Truncates input at 72 bytes |
| PBKDF2 | 600,000 iterations of HMAC-SHA-256 | When FIPS-140 compliance is required |
- Use your language’s well-maintained library (for example
password_hash()in PHP,argon2-cffiin Python,argon2orbcryptin Node). Don’t implement the algorithm yourself. - These libraries generate and store a unique salt per password automatically.
- Store the algorithm and parameters with the hash (the standard encoded formats do this) so you can upgrade on login: verify with the old settings, then rehash with the new ones.
- Consider a pepper, a secret key kept outside the database (for example in a secrets manager), as defence in depth.
- Tune the cost so verification takes well under a second on your servers, and rate-limit login to stop the cost being used for denial of service.
Password rules
NIST SP 800-63B is clear that composition rules and forced expiry make passwords worse. Instead:
- Minimum length: 15 characters for passwords used as the only factor; 8 if MFA is also required.
- Maximum length: allow at least 64 characters.
- Allow every character, including spaces and Unicode. Normalise Unicode (NFKC or NFKD) before hashing so the same password always hashes the same way.
- No composition rules (“must contain a symbol”) and no periodic expiry.
- Block common and breached passwords (see below), and tell the user why.
- No hints, no security questions.
- Allow paste into password fields.
Checking for breached passwords
The free Pwned Passwords API uses k-anonymity, so you can check a password at sign-up or password change without sending it anywhere:
sha1 = SHA1(password).hex().upper()
prefix, suffix = sha1[:5], sha1[5:]
GET https://api.pwnedpasswords.com/range/{prefix}
Add-Padding: true
# Response: one "SUFFIX:COUNT" per line. Breached if your suffix appears with COUNT > 0.
No API key is needed for this endpoint. Fail open (allow the password) if the API is unreachable, rather than blocking sign-ups. For high volumes, you can download the whole dataset and query it locally.
Login forms that work with password managers
- Use
autocomplete="username"on the username field,autocomplete="current-password"on login andautocomplete="new-password"on sign-up and change-password forms. - Use a real
<form>with atype="password"input, and keep the username and password on the same page where you can. Multi-step forms should include the username (even hidden) on the password step. - Offer a show password toggle.
- Support
/.well-known/change-passwordas a redirect to your change-password page, so password managers can send users straight there.
Beyond passwords
- Offer passkeys (WebAuthn). They remove phishing and credential stuffing for users who adopt them. Mature libraries exist for most stacks.
- Offer TOTP 2FA and generate recovery codes. Treat SMS as the weakest option.
- Rate-limit and throttle login attempts per account and per IP, and detect credential stuffing (many accounts, few attempts each).
- Notify users of new sign-ins and of password and email changes.
- Make errors generic: “Incorrect email or password”, so attackers can’t tell which accounts exist.
- Password reset: single-use, short-lived, high-entropy tokens; invalidate other sessions after a reset.
- Never log passwords, including in request logs, error reports and analytics. Check your logging middleware.
- Compare secrets in constant time, and always serve login pages over HTTPS with HSTS.