Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/visualbean/hibp.net
A simple .NET wrapper for the HIBP (Have I been pwned?) Api
https://github.com/visualbean/hibp.net
csharp haveibeenpwned hibp netcore nuget security
Last synced: 7 days ago
JSON representation
A simple .NET wrapper for the HIBP (Have I been pwned?) Api
- Host: GitHub
- URL: https://github.com/visualbean/hibp.net
- Owner: VisualBean
- License: unlicense
- Created: 2018-01-27T21:00:04.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-08-02T22:10:10.000Z (over 2 years ago)
- Last Synced: 2025-01-08T10:32:36.098Z (27 days ago)
- Topics: csharp, haveibeenpwned, hibp, netcore, nuget, security
- Language: C#
- Homepage:
- Size: 104 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HIBP.NET
[![GitHub license](https://img.shields.io/github/license/VisualBean/HIBP.NET.svg)](https://github.com/VisualBean/HIBP.NET/blob/master/LICENSE) ![.NET Core](https://github.com/VisualBean/HIBP.NET/workflows/.NET%20Core/badge.svg) [![NuGet version](https://badge.fury.io/nu/HIBP.NET.svg)](https://badge.fury.io/nu/HIBP.NET)
![NuGet](https://img.shields.io/nuget/dt/HIBP.NET.svg)A .Net wrapper for the HIBP API.
The full API is supported;
* PwnedPasswords
* Breaches
* PastesFull credits given to Troy Hunt for creating and managing [Have I been pwned?](https://haveibeenpwned.com).
Usage:
===
## PwnedPasswords
```csharp
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
```csharp
// 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
```csharp
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.
```csharp
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.