Skip to content

Commit

Permalink
Merge 3136b35 into 6050ee1
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklog authored Jan 25, 2019
2 parents 6050ee1 + 3136b35 commit eaa9111
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,15 @@ If you prefer to avoid using helper functions, the following syntax is also avai
$passwordStatus = (new PasswordExposedChecker())->passwordExposed($password);
```

### SHA1 Hash
You can also supply the SHA1 hash instead of the plain text password, by using the following method.

```php
$passwordStatus = (new PasswordExposedChecker())->passwordExposedByHash($hash);
```

or...

```php
$passwordStatus = password_exposed_by_hash($hash);
```
10 changes: 10 additions & 0 deletions src/PasswordExposedFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@ function password_exposed($password)
{
return (new PasswordExposedChecker())->passwordExposed($password);
}

/**
* @param string $hash
*
* @return string
*/
function password_exposed_by_hash($hash)
{
return (new PasswordExposedChecker())->passwordExposedByHash($hash);
}
10 changes: 10 additions & 0 deletions tests/Unit/PasswordExposedByHashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ protected function setUp()
$this->checker = new PasswordExposedChecker();
}

public function testFunctionExists()
{
$this->assertTrue(function_exists('password_exposed_by_hash'));
}

/**
* @return array
*/
Expand All @@ -37,6 +42,7 @@ public function exposedPasswordHashProvider()
public function testExposedPasswords($hash)
{
$this->assertEquals($this->checker->passwordExposedByHash($hash), PasswordStatus::EXPOSED);
$this->assertEquals(password_exposed_by_hash($hash), PasswordStatus::EXPOSED);
}

public function testNotExposedPasswords()
Expand All @@ -45,6 +51,10 @@ public function testNotExposedPasswords()
$this->checker->passwordExposedByHash($this->getPasswordHashUnlikelyToBeExposed()),
PasswordStatus::NOT_EXPOSED
);
$this->assertEquals(
password_exposed_by_hash($this->getPasswordHashUnlikelyToBeExposed()),
PasswordStatus::NOT_EXPOSED
);
}

/**
Expand Down

0 comments on commit eaa9111

Please sign in to comment.