Skip to content

Commit 94e222c

Browse files
committed
Deprecate password_hash salt option
1 parent 156ac23 commit 94e222c

5 files changed

Lines changed: 35 additions & 8 deletions

File tree

ext/standard/password.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ PHP_FUNCTION(password_hash)
346346
if (options && (option_buffer = zend_symtable_str_find(options, "salt", sizeof("salt")-1)) != NULL) {
347347
char *buffer;
348348
size_t buffer_len = 0;
349+
350+
php_error_docref(NULL, E_DEPRECATED, "Use of the 'salt' option to password_hash is deprecated");
351+
349352
switch (Z_TYPE_P(option_buffer)) {
350353
case IS_STRING:
351354
buffer = estrndup(Z_STRVAL_P(option_buffer), Z_STRLEN_P(option_buffer));

ext/standard/tests/password/password_bcrypt_errors.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ NULL
2424
Warning: password_hash(): Invalid bcrypt cost parameter specified: 32 in %s on line %d
2525
NULL
2626

27+
Deprecated: password_hash(): Use of the 'salt' option to password_hash is deprecated in %s on line %d
28+
2729
Warning: password_hash(): Provided salt is too short: 3 expecting 22 in %s on line %d
2830
NULL
2931

32+
Deprecated: password_hash(): Use of the 'salt' option to password_hash is deprecated in %s on line %d
33+
3034
Warning: password_hash(): Provided salt is too short: 21 expecting 22 in %s on line %d
3135
NULL
3236

37+
Deprecated: password_hash(): Use of the 'salt' option to password_hash is deprecated in %s on line %d
38+
3339
Warning: password_hash(): Provided salt is too short: 3 expecting 22 in %s on line %d
3440
NULL
3541

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Test deprecated operation of password_hash()
3+
--FILE--
4+
<?php
5+
//-=-=-=-
6+
7+
8+
var_dump(password_hash("rasmuslerdorf", PASSWORD_BCRYPT, array("cost" => 7, "salt" => "usesomesillystringforsalt")));
9+
10+
var_dump(password_hash("test", PASSWORD_BCRYPT, array("salt" => "123456789012345678901" . chr(0))));
11+
12+
echo "OK!";
13+
?>
14+
--EXPECTF--
15+
Deprecated: password_hash(): Use of the 'salt' option to password_hash is deprecated in %s on line %d
16+
string(60) "$2y$07$usesomesillystringfore2uDLvp1Ii2e./U9C8sBjqp8I90dH6hi"
17+
18+
Deprecated: password_hash(): Use of the 'salt' option to password_hash is deprecated in %s on line %d
19+
string(60) "$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y"
20+
OK!
21+

ext/standard/tests/password/password_hash.phpt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,9 @@ $hash = password_hash("foo", PASSWORD_BCRYPT);
1010

1111
var_dump($hash === crypt("foo", $hash));
1212

13-
var_dump(password_hash("rasmuslerdorf", PASSWORD_BCRYPT, array("cost" => 7, "salt" => "usesomesillystringforsalt")));
14-
15-
var_dump(password_hash("test", PASSWORD_BCRYPT, array("salt" => "123456789012345678901" . chr(0))));
16-
1713
echo "OK!";
1814
?>
1915
--EXPECT--
2016
int(60)
2117
bool(true)
22-
string(60) "$2y$07$usesomesillystringfore2uDLvp1Ii2e./U9C8sBjqp8I90dH6hi"
23-
string(60) "$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y"
24-
OK!
25-
18+
OK!

ext/standard/tests/password/password_hash_error.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ NULL
4141
Warning: password_hash() expects parameter 1 to be string, array given in %s on line %d
4242
NULL
4343

44+
Deprecated: password_hash(): Use of the 'salt' option to password_hash is deprecated in %s on line %d
45+
4446
Warning: password_hash(): Non-string salt parameter supplied in %s on line %d
4547
NULL
4648

49+
Deprecated: password_hash(): Use of the 'salt' option to password_hash is deprecated in %s on line %d
50+
4751
Warning: password_hash(): Provided salt is too short: 4 expecting 22 in %s on line %d
4852
NULL

0 commit comments

Comments
 (0)