Coder Social home page Coder Social logo

jfversluis / beenpwned.api Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 2.0 45 KB

.NET Wrapper library for the haveibeenpwned.com API

Home Page: https://haveibeenpwned.com

License: MIT License

C# 100.00%
api api-wrapper dotnet-standard pwned have-i-been-pwned dotnet pcl dotnetstandard

beenpwned.api's Introduction

Build status NuGet

BeenPwned.Api

.NET Wrapper library for the haveibeenpwned.com API

Platform support

Platform Version
.NET 4.5 & 4.6
.NET Standard 1.3
PCL Profile 111

Documentation

/// <summary>
/// A client which contains all functionality to communicate with the public haveibeenpwned.com API.
/// More information: https://haveibeenpwned.com/API/
/// </summary>
public interface IBeenPwnedClient : IDisposable
{
    /// <summary>
    /// Retrieves all breaches from the API. Including breaches marked as sensitive and retired.
    /// Full details are returned.
    /// </summary>
    /// <param name="domain">Filter breaches by domain. For example: abobe.com</param>
    /// <returns>List of all breaches currently in the API</returns>
    Task<IEnumerable<Breach>> GetAllBreaches(string domain = "");

    /// <summary>
    /// Retrieves a list of all data class available in the API.
    /// From the API description:
    /// A "data class" is an attribute of a record compromised in a breach.
    /// For example, many breaches expose data classes such as "Email addresses" and "Passwords".
    /// The values returned by this service are ordered alphabetically in a string array
    /// and will expand over time as new breaches expose previously unseen classes of data.
    /// </summary>
    /// <returns>A list of strings representing data classes</returns>
    Task<IEnumerable<string>> GetAllDataClasses();

    /// <summary>
    /// Retrieves all breaches for a certain account.
    /// The public API will NOT return breaches marked as sensitive or retired.
    /// By default, unverified breaches aren't included, however these can be included with a switch.
    /// </summary>
    /// <param name="account">Username or emailaddress to retrieve the breaches for</param>
    /// <param name="domain">Filter breaches by domain. For example: abobe.com. A breach can be included more than once, if the have been comprimised on multiple occasions</param>
    /// <param name="truncateResponse">Setting this to true will return only the names of the breaches</param>
    /// <param name="includeUnverified">Includes unverified breaches in the results</param>
    /// <returns>A list of breaches relevant to the given parameters</returns>
    Task<IEnumerable<Breach>> GetBreachesForAccount(string account, string domain = "", bool truncateResponse = true, bool includeUnverified = false);

    /// <summary>
    /// Retrieves a list of "pastes" for the given account.
    /// A "paste" is information that has been "pasted" to a publicly facing website designed to share content such as Pastebin.
    /// These services are favoured by hackers due to the ease of anonymously sharing information and they're frequently the first place a breach appears.
    /// More information: https://haveibeenpwned.com/FAQs#Pastes
    /// </summary>
    /// <param name="account">Username to search for. Has to be a (valid) emailaddress.</param>
    /// <returns>A list of pastes for the given account</returns>
    Task<IEnumerable<Paste>> GetPastesForAccount(string account);

    /// <summary>
    /// Checks if a given password is in the list of known breached passwords.
    /// </summary>
    /// <param name="password">The password to be checked</param>
    /// <param name="originalPasswordIsAHash">Specifies if the value in the "password" parameter is a SHA1 hash</param>
    /// <param name="sendAsPostRequest">Optionally the request can be sent as a POST request to prevent possible URL logging</param>
    /// <returns></returns>
    Task<bool> GetPwnedPassword(string password, bool originalPasswordIsAHash = false, bool sendAsPostRequest = false);
}

License

The MIT License (MIT) see License file

beenpwned.api's People

Contributors

cayassoftware avatar depechie avatar jfversluis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

beenpwned.api's Issues

Add tests

A test project needs to be added covering as much code as possible

Support .NET Standard 2.0

Add support for the freshly released 2.0 version of .NET Standard!

Dependant on JSON.Net package upgrade.

No way to tell apart 'no result found' and other errors for Breaches and Pastes

Currently the API returns an exception of type BeenPwnedUnavailableException with a message "Not Found" when no breaches (or pastes) are found.

On the consumer-side this poses a bit of a challenge. There is no way, besides string comparison on the exception message, to tell if an actual error happened (rate limit hit or whatever) or the result just came up empty.

There are a few alternatives to this:

  • Return an empty IEnumerable.
  • Return an actual status code enum. Include this in the BeenPwnedUnavailableException.
  • Distinguish different exception types.
  • Leave it like this.
  • Some other option I'm forgetting.

IMHO it's not preferable to throw an exception for a simple thing like 'no result found'.

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.