55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
"time"
|
|
|
|
"go.jolheiser.com/pwn"
|
|
)
|
|
|
|
var (
|
|
client = pwn.New(pwn.WithHTTP(&http.Client{
|
|
Timeout: time.Second * 10,
|
|
}))
|
|
|
|
Version = "develop"
|
|
)
|
|
|
|
// If used in CI of any kind
|
|
// Exits with error code 1 if password has been pwned
|
|
// Exits with error code 0 if password has not been pwned
|
|
func main() {
|
|
offlineExportFlag := flag.String("offline-export", "", "Path to an offline export rather than hitting the web API")
|
|
paddingFlag := flag.Bool("padding", false, "Add padding to password checks - more secure, but slower")
|
|
flag.Parse()
|
|
|
|
args := flag.Args()
|
|
if len(args) == 0 {
|
|
fmt.Println("pwn needs a password to check")
|
|
os.Exit(1)
|
|
}
|
|
|
|
var count int
|
|
var err error
|
|
|
|
if *offlineExportFlag != "" {
|
|
start := time.Now()
|
|
count, err = client.CheckPasswordOffline(args[0], *offlineExportFlag)
|
|
fmt.Println(time.Now().Sub(start))
|
|
} else {
|
|
count, err = client.CheckPassword(args[0], *paddingFlag)
|
|
}
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
fmt.Printf("This password has been pwned %d times.\n", count)
|
|
if count > 0 {
|
|
os.Exit(1)
|
|
}
|
|
os.Exit(0)
|
|
}
|