Skip to content

ASP.NET Identity Password Validator against Pwned Passwords by Troy Hunt

License

Notifications You must be signed in to change notification settings

ridercz/Altairis.Services.PwnedPasswordsValidator

Repository files navigation

NuGet Status

Pwned Passwords Validator

This project is ASP.NET Identity Password Validator that checks candidate password against Pwned Passwords by Troy Hunt. If the password is found in leaked passwords, it's refused.

There is a blog article and live coding session recording available, but in Czech language only.

Basic use

  1. Install package Altairis.Services.PwnedPasswordsValidator.
  2. Register the PwnedPasswordsValidator class in the ConfigureServices method of your startup class, ie. with the default settings:
services.AddDefaultIdentity<IdentityUser>()
    .AddDefaultUI(UIFramework.Bootstrap4)
    .AddEntityFrameworkStores<ApplicationDbContext>()
    .AddPasswordValidator<PwnedPasswordsValidator<IdentityUser>>();

Configuration

There are two configuration parameters:

  • RequestTimeout - if the server does not respond within defined timeout (default is 5 seconds), the password is allowed and error is logged.
  • GetLocalizedErrorMessage - the Func<string> delegate that returns error message that is given to IdentityResult returned. Default error message is "Password was found in haveibeenpwned.com password dumps." For localization scenarios, you'll most likely to load the string from resources.

To configure the options, inject the PwnedPasswordsValidatorOptions class:

services.Configure<PwnedPasswordsValidatorOptions>(c => {
    c.RequestTimeout = TimeSpan.FromSeconds(10);
    c.GetLocalizedErrorMessage = () => "Your password has been pwned.";
});

Acknowledgements

Author & Legal

About

ASP.NET Identity Password Validator against Pwned Passwords by Troy Hunt

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published