From b75359931e3c5baaded6d0addb6d28f750dcd518 Mon Sep 17 00:00:00 2001 From: Andinus Date: Mon, 16 Mar 2020 17:29:15 +0530 Subject: Add initial version of orion --- cmd/orion/orion.go | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 cmd/orion/orion.go (limited to 'cmd') diff --git a/cmd/orion/orion.go b/cmd/orion/orion.go new file mode 100644 index 0000000..e3ce011 --- /dev/null +++ b/cmd/orion/orion.go @@ -0,0 +1,55 @@ +package main + +import ( + "os" + "time" + + "framagit.org/andinus/orion/hibp" + + "github.com/AlecAivazis/survey/v2" + "github.com/AlecAivazis/survey/v2/terminal" + "github.com/briandowns/spinner" + "github.com/fatih/color" +) + +func main() { + var pass string + + prompt := &survey.Password{ + Message: "Password:", + Help: "Enter password to be checked against HIBP's Database", + } + err := survey.AskOne(prompt, &pass, survey.WithValidator(survey.Required)) + if err == terminal.InterruptErr { + color.Yellow("Interrupt Received") + os.Exit(0) + } else if err != nil { + panic(err) + } + + s := spinner.New(spinner.CharSets[12], 32*time.Millisecond) + s.Start() + s.Color("cyan") + + // get password hash + hsh := hibp.GetHsh(pass) + + // get list of pwned passwords + list, err := hibp.GetPwned(hsh) + if err != nil { + color.Yellow(err.Error()) + os.Exit(1) + } + + // check if pass is pwned + pwn, fq := hibp.ChkPwn(list, hsh) + s.Stop() + + if pwn { + color.New(color.FgRed).Add(color.Bold).Println("\nPwned!") + color.Yellow("This password has been seen %s times before.", fq) + return + } + + color.Green("\nPassword wasn't found in Have I Been Pwned's Database") +} -- cgit 1.4.1-2-gfad0