Skip to content

bcrypt_sha256 hash then verify fails #27

Description

@miketheman

I was testing this today as a potential alternative for passlib with bcrypt 5, and found a blocking issue.

bcrypt_sha256.verify() returns False for a hash that bcrypt_sha256.hash() just produced from the same password in the same process. Happens with bcrypt==4.3.0 and bcrypt==5.0.0. Doesn't happen on passlib==1.7.4, so this looks like a libpass-side regression rather than a bcrypt-compat thing.

Reproducer

# pip install libpass==1.9.3 bcrypt==4.3.0
from passlib.hash import bcrypt_sha256

h = bcrypt_sha256.using(rounds=12).hash("password")
print("hash:  ", h)
print("verify:", bcrypt_sha256.verify("password", h))

Observed

hash:   $bcrypt-sha256$v=2,t=2b,r=12$TkheP1Z9v6iFcmKaS8WyLu$t81vvvUJi9VS7mino2oycdr2dTDMzKe
verify: False

Expected

verify: True. passlib==1.7.4 on the same Python and same bcrypt returns True.

Compatibility matrix

passlib package bcrypt hash → verify
passlib==1.7.4 4.3.0 True
libpass==1.9.3 4.3.0 False (this bug)
libpass==1.9.3 5.0.0 False (this bug)
libpass<=1.9.2 5.0.0 backend init throws (see note)

On libpass<=1.9.2 + bcrypt==5.0.0 no verify ever runs: the wrap-bug probe in _finalize_backend_mixin calls bcrypt.hashpw with a 255-byte secret, and bcrypt 5.0 rejects it with ValueError: password cannot be longer than 72 bytes....

v=1 is broken too (bcrypt_sha256.using(version=1, rounds=12)), so it's not the HMAC change in v=2.

Environment

  • Python 3.13
  • macOS (haven't tried other platforms)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions