Skip to content

Instantly share code, notes, and snippets.

@devinrader
Created June 13, 2018 13:49
Show Gist options
  • Save devinrader/beba1714c16ab6a8cdbb842317ae8c1a to your computer and use it in GitHub Desktop.
Save devinrader/beba1714c16ab6a8cdbb842317ae8c1a to your computer and use it in GitHub Desktop.
Using the PwnedPasswords library in a console app
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PwnedPasswords.Client;
using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
public static async Task Main(string[] args)
{
var services = new ServiceCollection();
ConfigureServices(services);
var provider = services.BuildServiceProvider();
var app = provider.GetService<Application>();
await app.Verify("password");
Console.Read();
}
private static void ConfigureServices(IServiceCollection services)
{
services.AddTransient<Application>();
services.AddLogging();
services.AddPwnedPasswordHttpClient(); // add the client to the container
}
}
public class Application
{
IPwnedPasswordsClient _client;
public Application(IPwnedPasswordsClient client)
{
_client = client;
}
public async Task Verify(string password)
{
var result = await _client.HasPasswordBeenPwned(password);
Console.WriteLine(result);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment