Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ext/standard/password.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ static zend_string* php_password_bcrypt_hash(const zend_string *password, zend_a
return NULL;
}

if (ZSTR_LEN(password) > 72) {
zend_error(E_NOTICE, "Passwords longer than 72 characters are truncated by bcrypt");
}

if (options && (zcost = zend_hash_str_find(options, "cost", sizeof("cost")-1)) != NULL) {
cost = zval_get_long(zcost);
}
Expand Down
25 changes: 25 additions & 0 deletions ext/standard/tests/password/bcrypt_72_char_limit.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
Test 72 character limit of bcrypt
--FILE--
<?php
$long_pass = str_repeat('a', 71);

$hash = password_hash($long_pass . 'a', PASSWORD_BCRYPT, array("cost" => 4));
var_dump(password_verify($long_pass . 'a', $hash));
var_dump(password_verify($long_pass . 'b', $hash));

$hash = password_hash($long_pass . 'aa', PASSWORD_BCRYPT, array("cost" => 4));
var_dump(password_verify($long_pass . 'aa', $hash));

echo "This is the unexpected behavior we warn about: password is different but password_verify returns true.\n";
var_dump(password_verify($long_pass . 'ab', $hash));

?>
--EXPECTF--
bool(true)
bool(false)

Notice: Passwords longer than 72 characters are truncated by bcrypt in %s on line %d
bool(true)
This is the unexpected behavior we warn about: password is different but password_verify returns true.
bool(true)
Loading