Skip to content

fix: raise ProtonCryptoPasswordTooLongError when password exceeds bcrypt's 72-byte limit - #12

Closed
Tadakai wants to merge 1 commit into
ProtonVPN:stablefrom
Tadakai:fix/bcrypt-password-too-long
Closed

fix: raise ProtonCryptoPasswordTooLongError when password exceeds bcrypt's 72-byte limit#12
Tadakai wants to merge 1 commit into
ProtonVPN:stablefrom
Tadakai:fix/bcrypt-password-too-long

Conversation

@Tadakai

@Tadakai Tadakai commented Jun 28, 2026

Copy link
Copy Markdown

Problem

When a user's password exceeds 72 bytes, bcrypt raises a raw ValueError
that propagates uncaught, causing the login to crash with no clear
feedback to the user.

Solution

This PR catches the ValueError raised by bcrypt.hashpw() in
hash_password_3() and re-raises it as a new ProtonCryptoPasswordTooLongError
exception (subclass of ProtonCryptoError), allowing callers to handle
it gracefully and display a meaningful message to the user.

This approach was suggested in PR #10 as the preferred solution over
silently truncating the password.

Changes

  • proton/session/exceptions.py: added ProtonCryptoPasswordTooLongError
  • proton/session/srp/util.py: catch ValueError from bcrypt and raise
    ProtonCryptoPasswordTooLongError

…ypt's 72-byte limit

Instead of letting bcrypt raise a raw ValueError, catch it and raise
a descriptive ProtonCryptoPasswordTooLongError so callers can handle
it gracefully and show a clear message to the user.

Fixes: ValueError: password cannot be longer than 72 bytes
@Tadakai Tadakai closed this by deleting the head repository Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant