An open API service indexing awesome lists of open source software.

https://github.com/ascorbic/use-pwned-passwords

React custom hook to check passwords against the HaveIBeenPwned API
https://github.com/ascorbic/use-pwned-passwords

Last synced: 7 days ago
JSON representation

React custom hook to check passwords against the HaveIBeenPwned API

Awesome Lists containing this project

README

          

## usePwnedPasswords custom hook

This is a custom React hook that adds support for checking password fields against Troy Hunt's Have I Been Pwned [passwords API](https://haveibeenpwned.com/Passwords). Uses the [hibp module](https://github.com/wKovacs64/hibp) for the heavy lifting.

### Usage

```jsx
import { usePwnedPasswords } from "use-pwned-passwords";

export const App = () => {
const [passwordValue, pwnedCount, fieldProps] = usePwnedPasswords();

return (

{pwnedCount ? (


Your password has been found in {pwnedCount} breaches.
Please choose a more secure one.


) : null}

Enter your password:



);
};
```

The password is checked onBlur. The `usePwnedPasswords()` function can optionally take a config object. Currently there is one option you can set: `defaultValue` which sets the default value of the password field, but I'm not sure why you would set that.

### Demo

[Open demo](https://use-pwned-passwords.netlify.com/).

To run locally, run `yarn demo`