Documentation
¶
Overview ¶
Package haveibeenpwned is a client for Troy Hunt's Have I Been Pwned API v3 (https://haveibeenpwned.com/API/v3), including the Pwned Passwords k-anonymity range API (https://api.pwnedpasswords.com).
Endpoints that query data for a specific account (GetBreachedAccount, GetPastedAccount) require an API key from https://haveibeenpwned.com/API/Key. All other endpoints, including PwnedPasswordCount, work without a key.
Index ¶
- Constants
- type Breach
- type DataClasses
- type HIBPErrorResponse
- type HaveIBeenPwned
- func (o *HaveIBeenPwned) GetBreachedAccount(ctx context.Context, email string, domain string, truncateResponse bool, ...) ([]Breach, error)
- func (o *HaveIBeenPwned) GetBreachedSite(ctx context.Context, site string) (*Breach, error)
- func (o *HaveIBeenPwned) GetBreaches(ctx context.Context, domain string) ([]*Breach, error)
- func (o *HaveIBeenPwned) GetDataClasses(ctx context.Context) (*DataClasses, error)
- func (o *HaveIBeenPwned) GetPastedAccount(ctx context.Context, email string) ([]*Paste, error)
- func (o *HaveIBeenPwned) PwnedPasswordCount(ctx context.Context, password string) (int, error)
- type Option
- type Paste
Constants ¶
const ( // UserAgent is the default User-Agent header sent with every request. // The HIBP API rejects requests without a User-Agent. UserAgent = "haveibeenpwned-go/1.0 (+https://github.com/marco-montesines/haveibeenpwned)" // Accept is the media type requested from the API. Accept = "application/json" // Endpoint is the default base URL of the HIBP v3 API. Endpoint = "https://haveibeenpwned.com/api/v3/" // PwnedPasswordsEndpoint is the default base URL of the Pwned Passwords range API. PwnedPasswordsEndpoint = "https://api.pwnedpasswords.com/" // Domain matches a syntactically valid ASCII domain name. Domain = `^(?:[_\-a-z0-9]+\.)*([\-a-z0-9]+\.)[\-a-z0-9]{2,63}$` // DomainUnicode matches a syntactically valid internationalized domain name. DomainUnicode = `^(?:[_\-\p{L}\d]+\.)*([\-\p{L}\d]+\.)[\-\p{L}\d]{2,63}$` )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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 time.Time `json:"AddedDate,omitempty"`
ModifiedDate time.Time `json:"ModifiedDate,omitempty"`
PwnCount int `json:"PwnCount,omitempty"`
Description string `json:"Description,omitempty"`
LogoPath string `json:"LogoPath,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"`
IsMalware bool `json:"IsMalware,omitempty"`
IsSubscriptionFree bool `json:"IsSubscriptionFree,omitempty"`
IsStealerLog bool `json:"IsStealerLog,omitempty"`
}
Breach describes a single breach in the HIBP corpus. See https://haveibeenpwned.com/API/v3#BreachModel.
type DataClasses ¶
type DataClasses []string
DataClasses is the list of data attributes compromised in a breach.
type HIBPErrorResponse ¶
type HIBPErrorResponse struct {
Message string `json:"message"`
Description string `json:"-"`
Code int `json:"statusCode"`
RetryAfter int `json:"-"`
}
HIBPErrorResponse is the error payload returned by the HIBP API for non-2xx responses. It implements the error interface. RetryAfter carries the Retry-After header value (in seconds) on 429 responses.
func (*HIBPErrorResponse) Error ¶
func (e *HIBPErrorResponse) Error() string
type HaveIBeenPwned ¶
type HaveIBeenPwned struct {
// contains filtered or unexported fields
}
HaveIBeenPwned is a client for the HIBP v3 and Pwned Passwords APIs. It is safe for concurrent use by multiple goroutines.
func New ¶
func New(accessKey string, opts ...Option) *HaveIBeenPwned
New returns a client for the HIBP v3 API. The accessKey may be empty if only endpoints that do not require authentication are used.
func (*HaveIBeenPwned) GetBreachedAccount ¶
func (o *HaveIBeenPwned) GetBreachedAccount(ctx context.Context, email string, domain string, truncateResponse bool, includeUnverified bool) ([]Breach, error)
GetBreachedAccount returns all breaches an account appears in. Requires an API key. A nil slice with a nil error means the account was not found in any breach. See https://haveibeenpwned.com/API/v3#BreachesForAccount.
func (*HaveIBeenPwned) GetBreachedSite ¶
GetBreachedSite returns a single breach by its name (the stable "Name" attribute, e.g. "Adobe"). No API key required. See https://haveibeenpwned.com/API/v3#SingleBreach.
func (*HaveIBeenPwned) GetBreaches ¶
GetBreaches returns all breaches in the system, optionally filtered by the domain the breach occurred on. No API key required. See https://haveibeenpwned.com/API/v3#AllBreaches.
func (*HaveIBeenPwned) GetDataClasses ¶
func (o *HaveIBeenPwned) GetDataClasses(ctx context.Context) (*DataClasses, error)
GetDataClasses returns all data classes in the system. No API key required. See https://haveibeenpwned.com/API/v3#AllDataClasses.
func (*HaveIBeenPwned) GetPastedAccount ¶
GetPastedAccount returns all pastes an account appears in. Requires an API key. A nil slice with a nil error means the account was not found in any paste. See https://haveibeenpwned.com/API/v3#PastesForAccount.
func (*HaveIBeenPwned) PwnedPasswordCount ¶
PwnedPasswordCount reports how many times a password appears in the Pwned Passwords corpus, using the k-anonymity range API: only the first five characters of the password's SHA-1 hash ever leave the process. A count of zero means the password was not found. No API key required. See https://haveibeenpwned.com/API/v3#PwnedPasswords.
type Option ¶
type Option func(*HaveIBeenPwned)
Option configures a HaveIBeenPwned client.
func WithBaseURL ¶
WithBaseURL replaces the HIBP v3 API base URL, e.g. for tests or proxies.
func WithHTTPClient ¶
WithHTTPClient replaces the default *http.Client.
func WithPwnedPasswordsBaseURL ¶
WithPwnedPasswordsBaseURL replaces the Pwned Passwords API base URL.
func WithUserAgent ¶
WithUserAgent replaces the default User-Agent header.
type Paste ¶
type Paste struct {
Source string `json:"Source,omitempty"`
Id string `json:"Id,omitempty"`
Title string `json:"Title,omitempty"`
Date time.Time `json:"Date,omitempty"`
EmailCount int `json:"EmailCount,omitempty"`
}
Paste describes a single paste containing a searched account. See https://haveibeenpwned.com/API/v3#PasteModel.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
hibp
command
Command hibp is a command line interface and HTTP API server for Troy Hunt's Have I Been Pwned API v3, built on the github.com/marco-montesines/haveibeenpwned library.
|
Command hibp is a command line interface and HTTP API server for Troy Hunt's Have I Been Pwned API v3, built on the github.com/marco-montesines/haveibeenpwned library. |
|
examples
|
|
|
quickstart
command
A minimal example of the haveibeenpwned library.
|
A minimal example of the haveibeenpwned library. |