note 129484 added to function.password-hash
| From: | fullstadev@gmail.com | Date: | Tue, 14 May 2024 12:48:39 +0000 |
| Subject: | note 129484 added to function.password-hash | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221324@lists.php.net to get a copy of this message | ||
Similar to another post made here about the use of strings holding null-bytes within
password_hash(), I wanted to be a little more precise, as we've had quite some issues now.
I've had a project of an application generating random hashes (CSPRN). What they've done
is that they've used random_bytes(32), and the applied password_hash() to that obtained string,
with the bcrypt algorithm.
This on one side led to the fact that sometimes, random_bytes() generated a string with null-bytes,
actually resulting to an error in their call to password_hash() (PHP v 8.2.18). Thanks to that
("Bcrypt password must not contain a null character") I modified the the function
generating random hashes to encoding the obtained binary random string with random_bytes() using
bin2hex() (or base64 or whatever), to assure that the string to be hashed has no null-bytes.
I then just wanted to add that, when you use the bcrypt algorithm, make sure to remember that bcrypt
truncates your password at 72 characters. When encoding your random string (e.g. generated using
random_bytes()), this will convert your string from binary to hex representation, e.g. doubling its
length. What you generally want is that your entire password is still contained within the 72
characters limit, to be sure that your entire "random information" gets hashes, and not
only part of it.
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.131 (proxied: 84.20.52.6)
----
Manual Page -- https://php.net/manual/en/function.password-hash.php
Edit -- https://main.php.net/note/edit/129484
Del: integrated -- https://main.php.net/note/delete/129484/integrated
Del: useless -- https://main.php.net/note/delete/129484/useless
Del: bad code -- https://main.php.net/note/delete/129484/bad+code
Del: spam -- https://main.php.net/note/delete/129484/spam
Del: non-english -- https://main.php.net/note/delete/129484/non-english
Del: in docs -- https://main.php.net/note/delete/129484/in+docs
Del: other reasons-- https://main.php.net/note/delete/129484
Reject -- https://main.php.net/note/reject/129484
Search -- https://main.php.net/manage/user-notes.php