mattevans / pwned-passwords

🔐Go client library for checking values against compromised HIBP Pwned Passwords
MIT License
85 stars 7 forks source link
golang hibp password-safety passwords pwned-passwords

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!