Created
June 13, 2018 13:49
-
-
Save devinrader/beba1714c16ab6a8cdbb842317ae8c1a to your computer and use it in GitHub Desktop.
Using the PwnedPasswords library in a console app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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