TL;DR: bcrypt ignores any bytes after the first 72 bytes, this is due to bcrypt being based on the Blowfish cipher which has this limitation.bcrypt has been a commonly used password hashing algorithm for decades, it鈥檚 slow by design, includes built-in salting, and has protected countless systems from brute-force attacks.But despite its solid reputation, it also has a few hidden limitations worth knowing about.Let鈥檚 take a look at this code:import bcrypt password_1 = b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1" password_2 = b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2" hashed_password1 = bcrypt.hashpw(password_1, bcrypt.gensalt()) if bcrypt.checkpw(password_2, hashed_password1): print("Good password") else: print("Bad password")The code takes a string (as bytes) starting with 72 a鈥檚 and ending with 1, hashes it using bcrypt.hashpw, and then checks the same string ending with 2 this time against the hashed password.The output should be Bad password, right ?Let鈥檚 run the code, and see the output:bcrypt.checkpw returns TrueThe code shows Good password, but why ????Turns out that bcrypt is based on the Blowfish cipher, which only encrypts the first 72 bytes, this limitation is therefore inherited by bcrypt.The Blowfish algorithm uses an 18-element P-box, where each element is a 32-bit (4-byte) subkey. Therefore, the total P-box size is 18 * 4 bytes (72 bytes).This means that if the password is longer than 72 bytes, the bcrypt algorithm will only encrypt the first 72 bytes, and the rest will be ignored.bcrypt鈥檚 72-byte limit applies to bytes, not characters. This means that passwords with non-ASCII characters (like emojis or accented letters) may reach the limit even sooner, since UTF-8 encoding can use more than 1 byte per character.If you don鈥檛 want to worry about this limitation, you have several alternatives:Use a different algorithm, like Argon2, which does not have this limitation (Awarded the Password H...
First seen: 2025-11-16 22:56
Last seen: 2025-11-16 22:56