Skip to content

Commit

Permalink
Fixes big bug where password_needs_rehash didn't get options passed
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremykendall committed Jan 29, 2014
1 parent c602a25 commit c7a4aac
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ before_script:
- composer self-update
- composer install --prefer-dist

script: phpunit
script: phpunit -c travis.phpunit.xml

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
Expand Down
27 changes: 0 additions & 27 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="/tmp/jeremykendall/password-validator/coverage.xml"/>
<log type="coverage-html"
target="build/coverage"
charset="UTF-8"
Expand All @@ -18,30 +17,4 @@
lowUpperBound="40"
highLowerBound="70" />
</logging>
<listeners>
<listener class="League\PHPUnitCoverageListener\Listener">
<arguments>
<array>
<element key="printer">
<object class="League\PHPUnitCoverageListener\Printer\StdOut"/>
</element>
<element key="hook">
<object class="League\PHPUnitCoverageListener\Hook\Travis"/>
</element>
<element key="namespace">
<string>JeremyKendall\Password</string>
</element>
<element key="repo_token">
<string>KusjEdb4FdcqrUZejvepYNdVyAeZBTHcq</string>
</element>
<element key="target_url">
<string>https://coveralls.io/api/v1/jobs</string>
</element>
<element key="coverage_dir">
<string>/tmp/jeremykendall/password-validator</string>
</element>
</array>
</arguments>
</listener>
</listeners>
</phpunit>
7 changes: 6 additions & 1 deletion src/JeremyKendall/Password/PasswordValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ public function isValid($password, $passwordHash, $identity = null)
);

$isValid = password_verify($password, $passwordHash);
$needsRehash = password_needs_rehash($passwordHash, PASSWORD_DEFAULT);

$needsRehash = password_needs_rehash(
$passwordHash,
PASSWORD_DEFAULT,
$this->getOptions()
);

if ($isValid === true) {
$this->resultInfo['code'] = ValidationResult::SUCCESS;
Expand Down
17 changes: 17 additions & 0 deletions tests/JeremyKendall/Password/Tests/PasswordValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ public function testPasswordIsValidAndIsRehashed()
$this->assertTrue(password_verify('password', $result->getPassword()));
}

public function testCostNineHashValidAndNotRehashedBecauseOptions()
{
$options = array('cost' => 9);
$passwordHash = password_hash('password', PASSWORD_DEFAULT, $options);
$this->assertStringStartsWith('$2y$09$', $passwordHash);

$this->validator->setOptions($options);
$result = $this->validator->isValid('password', $passwordHash);

$this->assertTrue($result->isValid());
$this->assertEquals(
ValidationResult::SUCCESS,
$result->getCode()
);
$this->assertNull($result->getPassword());
}

public function testPasswordIsInvalid()
{
$passwordHash = password_hash('passwordz', PASSWORD_DEFAULT);
Expand Down
40 changes: 40 additions & 0 deletions travis.phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/bootstrap.php" colors="true">
<testsuite name="all-tests">
<directory>tests</directory>
</testsuite>
<filter>
<whitelist>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="/tmp/jeremykendall/password-validator/coverage.xml"/>
</logging>
<listeners>
<listener class="League\PHPUnitCoverageListener\Listener">
<arguments>
<array>
<element key="printer">
<object class="League\PHPUnitCoverageListener\Printer\StdOut"/>
</element>
<element key="hook">
<object class="League\PHPUnitCoverageListener\Hook\Travis"/>
</element>
<element key="namespace">
<string>JeremyKendall\Password</string>
</element>
<element key="repo_token">
<string>KusjEdb4FdcqrUZejvepYNdVyAeZBTHcq</string>
</element>
<element key="target_url">
<string>https://coveralls.io/api/v1/jobs</string>
</element>
<element key="coverage_dir">
<string>/tmp/jeremykendall/password-validator</string>
</element>
</array>
</arguments>
</listener>
</listeners>
</phpunit>

0 comments on commit c7a4aac

Please sign in to comment.