diff --git a/README.md b/README.md index f29be47..4b1bb09 100644 --- a/README.md +++ b/README.md @@ -2,25 +2,13 @@ [![Go Reference](https://pkg.go.dev/badge/github.com/wneessen/go-hibp.svg)](https://pkg.go.dev/github.com/wneessen/go-hibp) [![Go Report Card](https://goreportcard.com/badge/github.com/wneessen/go-hibp)](https://goreportcard.com/report/github.com/wneessen/go-hibp) [![Build Status](https://api.cirrus-ci.com/github/wneessen/go-hibp.svg)](https://cirrus-ci.com/github/wneessen/go-hibp) +This Go package provides an simple to use interface to the excellent +"[Have I Been Pwned](https://haveibeenpwned.com/API/v3)" (HIBP) API by Troy Hunt. + +**Completeness:** This packages is still WIP. So far the "Pwned Passwords" API and parts of the "Breaches" +API have been implemented. + ## Usage - -### Pwned Passwords API -```go -package main - -import ( - "fmt" - "github.com/wneessen/go-hibp" -) - -func main() { - hc := New() - m, _, err := hc.PwnedPassword.CheckPassword("test123") - if err != nil { - panic(err) - } - if m != nil && m.Count != 0 { - fmt.Println("Your password was found in the pwned passwords DB") - } -} -``` \ No newline at end of file +Have a look at the [GoDocs Reference](https://pkg.go.dev/github.com/wneessen/go-hibp) for details on how to implement +access to the HIBP API with this package or check out the examples for the different APIs in the [examples](examples) +directory. diff --git a/examples/pwned-password/check-password-withpadding.go b/examples/pwned-password/check-password-withpadding.go new file mode 100644 index 0000000..107c28c --- /dev/null +++ b/examples/pwned-password/check-password-withpadding.go @@ -0,0 +1,22 @@ +package main + +import ( + "fmt" + hibp "github.com/wneessen/go-hibp" +) + +func main() { + hc := hibp.New(hibp.WithPwnedPadding()) + if hc == nil { + panic("failed to create HIBP client") + } + + m, _, err := hc.PwnedPassApi.CheckPassword("test") + if err != nil { + panic(err) + } + if m != nil && m.Count != 0 { + fmt.Printf("Your password with the hash %q was found %d times in the pwned passwords DB\n", + m.Hash, m.Count) + } +} diff --git a/examples/pwned-password/check-password.go b/examples/pwned-password/check-password.go new file mode 100644 index 0000000..c6996b8 --- /dev/null +++ b/examples/pwned-password/check-password.go @@ -0,0 +1,22 @@ +package main + +import ( + "fmt" + hibp "github.com/wneessen/go-hibp" +) + +func main() { + hc := hibp.New() + if hc == nil { + panic("failed to create HIBP client") + } + + m, _, err := hc.PwnedPassApi.CheckPassword("test") + if err != nil { + panic(err) + } + if m != nil && m.Count != 0 { + fmt.Printf("Your password with the hash %q was found %d times in the pwned passwords DB\n", + m.Hash, m.Count) + } +} diff --git a/examples/pwned-password/check-sha1.go b/examples/pwned-password/check-sha1.go new file mode 100644 index 0000000..71a7c30 --- /dev/null +++ b/examples/pwned-password/check-sha1.go @@ -0,0 +1,23 @@ +package main + +import ( + "fmt" + hibp "github.com/wneessen/go-hibp" +) + +func main() { + hc := hibp.New() + if hc == nil { + panic("failed to create HIBP client") + } + + pwHash := "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3" // represents the PW: "test" + m, _, err := hc.PwnedPassApi.CheckSHA1(pwHash) + if err != nil { + panic(err) + } + if m != nil && m.Count != 0 { + fmt.Printf("Your password with the hash %q was found %d times in the pwned passwords DB\n", + m.Hash, m.Count) + } +}