Skip to content

Commit 908ed8e

Browse files
authored
Merge pull request #21 from nicklog/feature/password_by_hash
add "by_hash" function
2 parents 6050ee1 + 3136b35 commit 908ed8e

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,15 @@ If you prefer to avoid using helper functions, the following syntax is also avai
5757
$passwordStatus = (new PasswordExposedChecker())->passwordExposed($password);
5858
```
5959

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

6263
```php
6364
$passwordStatus = (new PasswordExposedChecker())->passwordExposedByHash($hash);
6465
```
66+
67+
or...
68+
69+
```php
70+
$passwordStatus = password_exposed_by_hash($hash);
71+
```

src/PasswordExposedFunction.php

+10
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,13 @@ function password_exposed($password)
1111
{
1212
return (new PasswordExposedChecker())->passwordExposed($password);
1313
}
14+
15+
/**
16+
* @param string $hash
17+
*
18+
* @return string
19+
*/
20+
function password_exposed_by_hash($hash)
21+
{
22+
return (new PasswordExposedChecker())->passwordExposedByHash($hash);
23+
}

tests/Unit/PasswordExposedByHashTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ protected function setUp()
1717
$this->checker = new PasswordExposedChecker();
1818
}
1919

20+
public function testFunctionExists()
21+
{
22+
$this->assertTrue(function_exists('password_exposed_by_hash'));
23+
}
24+
2025
/**
2126
* @return array
2227
*/
@@ -37,6 +42,7 @@ public function exposedPasswordHashProvider()
3742
public function testExposedPasswords($hash)
3843
{
3944
$this->assertEquals($this->checker->passwordExposedByHash($hash), PasswordStatus::EXPOSED);
45+
$this->assertEquals(password_exposed_by_hash($hash), PasswordStatus::EXPOSED);
4046
}
4147

4248
public function testNotExposedPasswords()
@@ -45,6 +51,10 @@ public function testNotExposedPasswords()
4551
$this->checker->passwordExposedByHash($this->getPasswordHashUnlikelyToBeExposed()),
4652
PasswordStatus::NOT_EXPOSED
4753
);
54+
$this->assertEquals(
55+
password_exposed_by_hash($this->getPasswordHashUnlikelyToBeExposed()),
56+
PasswordStatus::NOT_EXPOSED
57+
);
4858
}
4959

5060
/**

0 commit comments

Comments
 (0)