Merge pull request #2 from wneessen/breaches

Updated README.md and added examples
This commit is contained in:
Winni Neessen 2021-09-21 20:43:12 +02:00 committed by GitHub
commit a98a5c94ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 21 deletions

View file

@ -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")
}
}
```
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.

View file

@ -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)
}
}

View file

@ -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)
}
}

View file

@ -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)
}
}