HIBP.NET 3.0.1

dotnet add package HIBP.NET --version 3.0.1                
NuGet\Install-Package HIBP.NET -Version 3.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HIBP.NET" Version="3.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HIBP.NET --version 3.0.1                
#r "nuget: HIBP.NET, 3.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install HIBP.NET as a Cake Addin
#addin nuget:?package=HIBP.NET&version=3.0.1

// Install HIBP.NET as a Cake Tool
#tool nuget:?package=HIBP.NET&version=3.0.1                

HIBP.NET

A .Net wrapper for the HIBP API. The full API is supported;

  • PwnedPasswords
  • Breaches
  • Pastes

Full credits given to Troy Hunt for creating and managing Have I been pwned?.

Usage:

PwnedPasswords

async Task MyMethodPlainTextPasswordAsync()
{
    var client = new HIBP.PwnedPasswordClient("MyAwesomeService");
    int pwns = await client.IsPasswordPwnedAsync("password1");
    if (pwns > 0)
    {
        Console.WriteLine($"Password has been pwned: {pwns} times");
    }
}

// or

async Task MyMethodPreHashedPasswordAsync()
{
    var client = new HIBP.PwnedPasswordClient("MyAwesomeService");
    int pwns = await client.IsPasswordPwnedAsync("password1".ToSHA1(), isHash: true);
    if (pwns > 0)
    {
        Console.WriteLine("Password has been pwned");
    }
}

With .Net core dependency injection.

Adding the clients

// for all clients
public void ConfigureServices(IServiceCollection services)
{
    services.AddHIBP(c =>
    {
        c.ApiKey = new ApiKey("MyKey");
        c.ServiceName = "MyAwesomeService";
    });
}

or you can add individual clients

public void ConfigureServices(IServiceCollection services)
{
    services.AddBreachClient(c =>
    {
        c.ApiKey = new ApiKey("MyKey");
        c.ServiceName = "MyAwesomeService";
    });
    
    services.AddPwnedPasswordsClient("MyAwesomeService");
    
    services.AddPastesClient(new ApiKey("MyKey"), "MyAwesomeService");
 }

Inject the client.

class MyClass
{
    private readonly IBreachClient breachClient;
    public MyClass(IBreachClient breachClient)
    {
        this.breachClient = breachClient;
    }
    
    public async Task GetBreachesAsync()
    {
        var breaches = this.breachClient.GetBreachesAsync();
        // do stuff..
    }
}

Changes

Breaking changes are coming in version 3.0

  • ApiKey has been refactored to be a class of its own. (BREAKING)
  • Renamed API clients from {name}Api to {name}Client (BREAKING)
  • Renamed parameters to better match usage.
  • Added pastes client.
  • Added extension for easier injection and setup in netcore projects.
  • Expose ToSHA1(). for easy hashing when using the PwnedPasswords API.
  • Update to .Net core 3.1
  • Changed license from MIT to Unlicense.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.1 3,681 12/9/2020
2.0.0 1,992 7/22/2019
1.1.1 6,447 5/23/2018
1.1.0 1,446 5/20/2018
1.0.2 2,485 2/25/2018