Re: [RFC] Throw error for passwords longer than 72 bytes in password_hash() with bcrypt

From: Date: Wed, 30 Sep 2026 08:14:20 +0000
Subject: Re: [RFC] Throw error for passwords longer than 72 bytes in password_hash() with bcrypt
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-132709@lists.php.net to get a copy of this message
> Exactly, and my proposal aims to throw a ValueError in those cases, indicating that it is a > programming error to pass anything other than password. The tradeoff is that actual passwords longer > than 72 bytes are no longer supported. I think that is acceptable. The function signature already says it will accept a string value, and it is already working under this contract. Limiting it to 72 bytes does not ensure the passed string is a password, and it is merely an implementation detail for bcrypt. The php.net manual page for password_hash also already mentions the 72-byte truncation behavior. Passing an invalid hashing algorithm, unsupported algorithm options, RNG failures, etc., are indeed programmer/program errors, and it already throws hard exceptions/errors in those cases. I wouldn't also characterize the two vulnerabilities mentioned in the RFC (in other software) as related. In PHP, the salt is now (PHP 7+) always generated automatically, and the password_hash() output is not limited to a certain length. While I agree that vulnerable software could be written around bcrypt's 72-byte behavior, it would not be a strong relation to PHP. Thank you, Ayesh.

« previous php.internals (#132709) next »