Git Product home page Git Product logo

pwnedpasswords's Introduction

PwnedPasswords logo

Pwned Passwords are hundreds of millions of real world passwords exposed in data breaches. This exposure makes them unsuitable for ongoing use as they're at much greater risk of being used to take over other accounts. They're searchable online below as well as being downloadable for use in other online system

Build status

client-nuget validator-nuget

This repository contains two libraries, PwnedPasswords.Client and PwnedPasswords.Validator.

Why should you care?

As per Troy Hunt's website:

Password reuse and credential stuffing

Password reuse is normal. It's extremely risky, but it's so common because it's easy and people aren't aware of the potential impact. Attacks such as credential stuffing take advantage of reused credentials by automating login attempts against systems using known emails and password pairs.

NIST's guidance: check passwords against those obtained from previous data breaches

The Pwned Passwords service was created after NIST released guidance specifically recommending that user-provided passwords be checked against existing data breaches . The rationale for this advice and suggestions for how applications may leverage this data is described in detail in the blog post titled Introducing 306 Million Freely Downloadable Pwned Passwords.

This package provides an IPasswordValidator for ASP.NET Core Identity that checks whether the provided password appears on the have I been pwned list.

PwnedPasswords.Client

.NET Core 2.1 introduces HTTPClient factory, an "opinionated factory for creating HttpClient instances". It allows easy configuration of HttpClient instances, manages their lifetime, and enables easy addition of common functionality, such as retry logic for transient HTTP errors.

PwnedPasswords.Client provides the IPwnedPasswordsClient type, which can be used to easily access the PwnedPasswords API. It hooks into the Microsoft.Extensions.DependencyInjection / ASP.NET Core DI container, and can be configured with optional fault handling etc as required.

Getting started

Install the PwnedPasswords.Client NuGet package into your project using:

dotnet add package PwnedPasswords.Client

When you install the package, it should be added to your csproj. Alternatively, you can add it directly by adding:

<PackageReference Include="PwnedPasswords.Client" Version="1.0.0" />

Add to your dependency injection container in Startup.ConfigureServices using the AddPwnedPasswordHttpClient() extension method. You can further configure the IHttpClientBuilder to add fault handling for example.

public void ConfigureServices(IServiceCollection services)
{
    services.AddPwnedPasswordHttpClient()                      // add the client to the container
        .AddTransientHttpErrorPolicy(p => p.RetryAsync(3))     //configure the HttpClient used by the IPwnedPasswordsClient
        .AddPolicyHandler(Policy.TimeoutAsync<HttpResponseMessage>(TimeSpan.FromSeconds(2)));

    // other configuration
}

You can also choose the minimum number of times a password must have appeared in a breach for it to be considered "pwned". So for example, if you only want to consider passwords that have appeared 20 times as pwned you can use the overload on AddPwnedPasswordHttpClient():

public void ConfigureServices(IServiceCollection services)
{
    services.AddPwnedPasswordHttpClient(minimumFrequencyToConsiderPwned: 20);
}

You can also configure this using the standard Options pattern in ASP.NET Core, for example by loading the required value from a JSON value.

public void ConfigureServices(IServiceCollection services)
{
    services.AddPwnedPasswordHttpClient();
    services.Configure<PwnedPasswordsClientOptions>(Configuration.GetSection("PwnedPasswords"));
}

PwnedPasswords.Validator

PwnedPasswords.Validator contains an implementation of an ASP.NET Core Identity IPasswordValidator that verifies the provided password has not been exposed in a known security breach.

Getting started

Install the PwnedPasswords.Validator NuGet package into your project using:

dotnet add package PwnedPasswords.Validator_

When you install the package, it should be added to your csproj. Alternatively, you can add it directly by adding:

<PackageReference Include="PwnedPasswords.Validator_" Version="1.0.0" />

You can add the PwnedPasswords ASP.NET Core Identity Validator to your IdentityBuilder in Startup.ConfigureServices using the AddPwnedPasswordValidator() extension method.

public void ConfigureServices(IServiceCollection services)
{
     services.AddDefaultIdentity<IdentityUser>()
        .AddEntityFrameworkStores<ApplicationDbContext>()
        .AddPwnedPasswordValidator<IdentityUser>(); // add the validator

    // other configuration
}

As for the PwnedPasswordsClient library, you can customize the minimum number of times a password must have appeared in a breach for it to be considered invalid by the validator. For example:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDefaultIdentity<IdentityUser>()
    .AddEntityFrameworkStores<ApplicationDbContext>()
    .AddPwnedPasswordValidator<IdentityUser>(); // add the validator

    // set the minimum password to consider the password pwned
    services.Configure<PwnedPasswordsClientOptions>(Configuration.GetSection("PwnedPasswords"));
}

Additional Resources

pwnedpasswords's People

Contributors

andrewlock avatar mattlorimor avatar seanfarrow avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.