divineomega / password_exposed
This PHP package provides a `password_exposed` helper function, that uses the haveibeenpwned.com API to check if a password has been exposed in a data breach.
Fund package maintenance!
DivineOmega
Installs: 1 481 434
Dependents: 6
Suggesters: 0
Security: 0
Stars: 216
Watchers: 11
Forks: 34
Open Issues: 5
Requires
- php: ^7.1||^8.0
- divineomega/do-file-cache-psr-6: ^2.0
- divineomega/psr-18-guzzle-adapter: ^1.0
- nyholm/psr7: ^1.0
- paragonie/certainty: ^2.4
- php-http/discovery: ^1.6
- psr/cache: ^1.0
- psr/http-client: ^1.0
- psr/http-factory-implementation: ^1.0
- psr/http-message: ^1.0
- psr/http-message-implementation: ^1.0
Requires (Dev)
- fzaninotto/faker: ^1.7
- kriswallsmith/buzz: ^1.0
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^7.0||^8.0
- symfony/cache: ^4.2.12
- vimeo/psalm: ^4
README
This PHP package provides a password_exposed
helper function, that uses the haveibeenpwned.com API to check if a password has been exposed in a data breach.
Installation
The password_exposed
package can be easily installed using Composer. Just run the following command from the root of your project.
composer require "divineomega/password_exposed"
If you have never used the Composer dependency manager before, head to the Composer website for more information on how to get started.
Usage
To check if a password has been exposed in a data breach, just pass it to the password_exposed
method.
Here is a basic usage example:
switch(password_exposed('hunter2')) { case PasswordStatus::EXPOSED: // Password has been exposed in a data breach. break; case PasswordStatus::NOT_EXPOSED: // Password has not been exposed in a known data breach. break; case PasswordStatus::UNKNOWN: // Unable to check password due to an API error. break; }
If you prefer to avoid using helper functions, the following syntax is also available.
$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.
$passwordStatus = (new PasswordExposedChecker())->passwordExposedByHash($hash);
or...
$passwordStatus = password_exposed_by_hash($hash);