MDL-52283 core: password_hash() deprecation in PHP7

This commit is contained in:
Tony Levi 2015-08-03 16:16:03 +09:30 committed by Marina Glancy
parent c18acb8997
commit 79d4558a58
3 changed files with 7 additions and 5 deletions

View File

@ -309,7 +309,7 @@ class auth_db_testcase extends advanced_testcase {
require_once($CFG->libdir.'/password_compat/lib/password.php'); require_once($CFG->libdir.'/password_compat/lib/password.php');
set_config('passtype', 'saltedcrypt', 'auth/db'); set_config('passtype', 'saltedcrypt', 'auth/db');
$auth->config->passtype = 'saltedcrypt'; $auth->config->passtype = 'saltedcrypt';
$user3->pass = password_hash('heslo', PASSWORD_BCRYPT, array('salt' => 'best_salt_ever_moodle_rocks_dont_tell')); $user3->pass = password_hash('heslo', PASSWORD_BCRYPT);
$DB->update_record('auth_db_users', $user3); $DB->update_record('auth_db_users', $user3);
$this->assertTrue($auth->user_login('u3', 'heslo')); $this->assertTrue($auth->user_login('u3', 'heslo'));

View File

@ -16,6 +16,8 @@ Our changes:
* Added the following require_once() to the test files: * Added the following require_once() to the test files:
global $CFG; global $CFG;
require_once($CFG->dirroot . '/lib/password_compat/lib/password.php'); require_once($CFG->dirroot . '/lib/password_compat/lib/password.php');
* tests/PasswordHashTest.php supresses debugging from using salt in password_hash()
see MDL-52283
Library description: Library description:
==================== ====================

View File

@ -19,12 +19,12 @@ class PasswordHashTest extends PHPUnit_Framework_TestCase {
} }
public function testKnownSalt() { public function testKnownSalt() {
$hash = password_hash("rasmuslerdorf", PASSWORD_BCRYPT, array("cost" => 7, "salt" => "usesomesillystringforsalt")); $hash = @password_hash("rasmuslerdorf", PASSWORD_BCRYPT, array("cost" => 7, "salt" => "usesomesillystringforsalt"));
$this->assertEquals('$2y$07$usesomesillystringfore2uDLvp1Ii2e./U9C8sBjqp8I90dH6hi', $hash); $this->assertEquals('$2y$07$usesomesillystringfore2uDLvp1Ii2e./U9C8sBjqp8I90dH6hi', $hash);
} }
public function testRawSalt() { public function testRawSalt() {
$hash = password_hash("test", PASSWORD_BCRYPT, array("salt" => "123456789012345678901" . chr(0))); $hash = @password_hash("test", PASSWORD_BCRYPT, array("salt" => "123456789012345678901" . chr(0)));
if (version_compare(PHP_VERSION, '5.5.0', '<')) { if (version_compare(PHP_VERSION, '5.5.0', '<')) {
$this->assertEquals('$2y$10$KRGxLBS0Lxe3KBCwKxOzLexLDeu0ZfqJAKTubOfy7O/yL2hjimw3u', $hash); $this->assertEquals('$2y$10$KRGxLBS0Lxe3KBCwKxOzLexLDeu0ZfqJAKTubOfy7O/yL2hjimw3u', $hash);
} else { } else {
@ -33,12 +33,12 @@ class PasswordHashTest extends PHPUnit_Framework_TestCase {
} }
public function testNullBehavior() { public function testNullBehavior() {
$hash = password_hash(null, PASSWORD_BCRYPT, array("salt" => "1234567890123456789012345678901234567890")); $hash = @password_hash(null, PASSWORD_BCRYPT, array("salt" => "1234567890123456789012345678901234567890"));
$this->assertEquals('$2y$10$123456789012345678901uhihPb9QpE2n03zMu9TDdvO34jDn6mO.', $hash); $this->assertEquals('$2y$10$123456789012345678901uhihPb9QpE2n03zMu9TDdvO34jDn6mO.', $hash);
} }
public function testIntegerBehavior() { public function testIntegerBehavior() {
$hash = password_hash(12345, PASSWORD_BCRYPT, array("salt" => "1234567890123456789012345678901234567890")); $hash = @password_hash(12345, PASSWORD_BCRYPT, array("salt" => "1234567890123456789012345678901234567890"));
$this->assertEquals('$2y$10$123456789012345678901ujczD5TiARVFtc68bZCAlbEg1fCIexfO', $hash); $this->assertEquals('$2y$10$123456789012345678901ujczD5TiARVFtc68bZCAlbEg1fCIexfO', $hash);
} }