hibp

package module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2022 License: MIT Imports: 11 Imported by: 7

README

pwned-passwords

GoDoc Build Status Go Report Card license

A light-weight Go client for checking compromised passwords against HIBP Pwned Passwords.

Installation

go get -u github.com/mattevans/pwned-passwords

Usage

package main

import (
    "fmt"
    "net/http"
    "os"
    "time"

    hibp "github.com/mattevans/pwned-passwords"
)

func main() {
    // Init a client.
    client := hibp.NewClient()

    // Optional: Use a custom http client
    client.SetHTTPClient(&http.Client{
        Timeout: 3 * time.Second,
    })
	
    // Check to see if your given string is compromised.
    pwned, err := client.Compromised("string to check")
    if err != nil {
        os.Exit(1)
    }

    if pwned {
        // Oh dear! 😱 -- You should avoid using that password
        fmt.Print("Found to be compromised")
    }
}

Contributing

If you've found a bug or would like to contribute, please create an issue here on GitHub, or better yet fork the project and submit a pull request!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	UserAgent  string
	BackendURL *url.URL
	// contains filtered or unexported fields
}

Client holds a connection to the HIBP API.

func NewClient

func NewClient() *Client

NewClient creates a new Client with the appropriate connection details and services used for communicating with the API.

func (*Client) Compromised added in v0.5.0

func (c *Client) Compromised(value string) (bool, error)

Compromised will build and execute a request to HIBP to check to see if the passed value is compromised or not.

func (*Client) Do

func (c *Client) Do(req *http.Request) ([]string, error)

Do sends an API request and returns the API response.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlPath string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlPath, which will be resolved to the BackendURL of the Client.

func (*Client) SetHTTPClient added in v0.5.0

func (c *Client) SetHTTPClient(client *http.Client) *Client

SetHTTPClient sets a *http.Client for the HIBP Client to use. Useful for customising timeout behaviour etc.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL