mirror of
https://github.com/wneessen/go-hibp.git
synced 2024-12-23 02:30:38 +01:00
Updated README.md and added examples/
This commit is contained in:
parent
213d2dc931
commit
e670c59a8d
4 changed files with 76 additions and 21 deletions
30
README.md
30
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")
|
||||
}
|
||||
}
|
||||
```
|
||||
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.
|
||||
|
|
22
examples/pwned-password/check-password-withpadding.go
Normal file
22
examples/pwned-password/check-password-withpadding.go
Normal 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)
|
||||
}
|
||||
}
|
22
examples/pwned-password/check-password.go
Normal file
22
examples/pwned-password/check-password.go
Normal 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)
|
||||
}
|
||||
}
|
23
examples/pwned-password/check-sha1.go
Normal file
23
examples/pwned-password/check-sha1.go
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue