gopwned

package module
Version: v0.0.0-...-ce15729 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2019 License: MIT Imports: 5 Imported by: 0

README

goPwned

Go Report Card GoDoc Build Status Coverage Status

A golang library for HaveIBeenPwned REST API - https://haveibeenpwned.com/

Installation

go get github.com/mavjs/goPwned

Usage

Breaches
Getting all breaches for an account
Get all breaches for an account across all domains.
import (
    "github.com/mavjs/goPwned"
    )

func main() {
    fmt.Println(gopwned.GetBreachesForAccount("foo@bar.com"))
}
Get all breaches for an account across a particular domain.
import (
    "github.com/mavjs/goPwned"
    )

func main() {
    fmt.Println(gopwned.GetBreachesForAccount("foo@bar.com", "adobe.com"))
}
Getting all breached sites in the system
Get all the details of each breach in the system
import (
    "github.com/mavjs/goPwned"
    )

func main() {
    fmt.Println(gopwned.AllBreaches())
}
Get all the details of breached site
import (
    "github.com/mavjs/goPwned"
    )

func main() {
    fmt.Println(gopwned.AllBreaches("adobe.com"))
}
Getting a single breached site in the system
import (
    "github.com/mavjs/goPwned"
    )

func main() {
    fmt.Println(gopwned.GetSingleBreachedSite("adobe"))
}
Getting all data classes in the system
import (
    "github.com/mavjs/goPwned"
    )

func main() {
    fmt.Println(gopwned.GetAllDataClasses())
}
Pastes
Getting all pastes for an account
import (
    "github.com/mavjs/goPwned"
    )

func main() {
    fmt.Println(gopwned.GetAllPastesForAccount("foo@bar.com"))
}
Pwned Passwords
import (
    "github.com/mavjs/goPwned"
    "crypto/sha1"
    )
func fakeinput() {
    inputPassword := "P@ssw0rd"
    h := sha1.New()
    h.Write([]byte(inputPassword))
    password := fmt.Sprintf("%X", h.Sum(nil)) // hash = "21BD12DC183F740EE76F27B78EB39C8AD972A757"

    return password
}

func main() {
    pwdhash := fakeinput()
    frange := pwdhash[0:5]

    karray, err := gopwned.PwnedPasswords(frange)
    str_karray := string(karray)
    respArray := strings.Split(str_karray, "\n")

    var result int
    for r := 0, lrange := pwdhash[5:40]; r < len(respArray); r++ {
        test, count := strings.Split(respArray[r], ":")
        count = strconv.ParseInt(count)
        if (test == lrange) {
            result = count
        }
        break;
    }

    fmt.Println("This password has been seen: ", count)
}

License

MIT

Documentation

Overview

Package gopwned implements the REST api of haveibeenpwned.com for easy querying

Index

Constants

View Source
const (
	Version        = "0.1"
	UserAgent      = "gopwned-api-client-" + Version
	MediaTypeV2    = "application/vnd.haveibeenpwned.v2+json"
	Endpoint       = "https://haveibeenpwned.com/api/v2/"
	PwnPwdEndpoint = "https://api.pwnedpasswords.com/range/"
)

Variables

This section is empty.

Functions

func PwnedPasswords

func PwnedPasswords(chars string) ([]byte, error)

Types

type Breach

type Breach struct {
	Name         string       `json:"Name,omitempty"`
	Title        string       `json:"Title,omitempty"`
	Domain       string       `json:"Domain,omitempty"`
	BreachDate   string       `json:"BreachDate,omitempty"`
	AddedDate    string       `json:"AddedDate,omitempty"`
	PwnCount     int          `json:"PwnCount,omitempty"`
	Description  string       `json:"Description,omitempty"`
	DataClasses  *DataClasses `json:"DataClasses,omitempty"`
	IsVerified   bool         `json:"IsVerified,omitempty"`
	IsFabricated bool         `json:"IsFabricated,omitempty"`
	IsSensitive  bool         `json:"IsSensitive,omitempty"`
	IsRetired    bool         `json:"IsRetired,omitempty"`
	IsSpamList   bool         `json:"IsSpamList,omitempty"`
	LogoType     string       `json:"LogoType,omitempty"`
}

func GetAllBreachedSites

func GetAllBreachedSites(domain string) ([]*Breach, error)

func GetAllBreachesForAccount

func GetAllBreachesForAccount(email, domain, truncateResponse string) ([]*Breach, error)

func GetBreachedSite

func GetBreachedSite(site string) ([]*Breach, error)

type Client

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

func NewClient

func NewClient(client *http.Client) *Client

func (*Client) GetAllBreachedSites

func (c *Client) GetAllBreachedSites(domain string) ([]*Breach, error)

func (*Client) GetAllBreachesForAccount

func (c *Client) GetAllBreachesForAccount(email, domain, truncateResponse string) ([]*Breach, error)

func (*Client) GetAllPastesForAccount

func (c *Client) GetAllPastesForAccount(account string) ([]*Paste, error)

func (*Client) GetBreachedSite

func (c *Client) GetBreachedSite(site string) ([]*Breach, error)

func (*Client) GetDataClasses

func (c *Client) GetDataClasses() (*DataClasses, error)

func (*Client) PwnedPasswords

func (c *Client) PwnedPasswords(chars string) ([]byte, error)

type DataClasses

type DataClasses []string

func GetDataClasses

func GetDataClasses() (*DataClasses, error)

type Paste

type Paste struct {
	Source     string `json:"Source,omitempty"`
	ID         string `json:"Id,omitempty"`
	Title      string `json:"Title,omitempty"`
	Date       string `json:"Date,omitempty"`
	EmailCount int    `json:"EmailCount,omitempty"`
}

func GetAllPastesForAccount

func GetAllPastesForAccount(account string) ([]*Paste, error)

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL