mirror of
https://github.com/storytold/artcraft-services.git
synced 2026-11-24 19:31:01 +01:00
## What was wrong bcrypt only uses the first 72 bytes of a password. Account creation, password change and password reset accepted longer passwords and hashed them, so everything after byte 72 was silently ignored. A user who changed only the tail of a long password hadn't really changed it, and a long passphrase was weaker than it looked. ## What changed - `password` crate: new `BCRYPT_MAX_PASSWORD_BYTES = 72`. `bcrypt_hash_password` returns a new `PasswordHashError::PasswordTooLong` instead of truncating (with a unit test at 72 and 73 bytes). - `validate_passwords` (account creation, password change) rejects longer passwords with a clear 400 message. - Password reset redemption rejects them with a new `PasswordTooLong` 400 error. Login (`bcrypt_confirm_password`) is unchanged, so existing accounts with longer passwords can still sign in; they just can't set a new one over 72 bytes. ## Checks - Run: `cargo test -p password` (6 passed); `SQLX_OFFLINE=true cargo check -p storyteller-web` (exit 0). - Not run: endpoint tests (need a live MySQL).