passage-go/gopass-cmd/main.go

52 lines
884 B
Go
Raw Normal View History

2017-01-25 17:58:37 +00:00
package main
import (
"fmt"
"os"
2017-01-25 20:13:26 +00:00
"golang.org/x/crypto/ssh/terminal"
2017-08-17 20:05:19 +00:00
passage "git.bullercodeworks.com/brian/passage-go"
2017-01-25 17:58:37 +00:00
)
func main() {
2017-01-25 20:13:26 +00:00
var pin, door string
2017-08-17 20:05:19 +00:00
p := passage.CreatePassage("")
2017-01-25 20:13:26 +00:00
for i := 1; i < len(os.Args); i++ {
switch i {
case 1:
pin = os.Args[i]
2017-08-17 20:05:19 +00:00
p.SetPin(pin)
fmt.Println("Checksum: " + p.GetChecksumAsString())
2017-01-25 20:13:26 +00:00
case 2:
door = os.Args[i]
}
}
getInput := (pin == "" && door == "")
for getInput {
if pin == "" {
fmt.Print("Pin: ")
pinBt, _ := terminal.ReadPassword(0)
fmt.Println("")
pin = string(pinBt)
}
if pin == "" {
continue
} else {
p.SetPin(pin)
fmt.Println("Checksum: " + p.GetChecksumAsString())
}
if door == "" {
fmt.Print("Door (leave empty to re-enter pin): ")
fmt.Scanln(&door)
}
if door == "" {
pin = ""
} else {
getInput = false
}
2017-01-25 17:58:37 +00:00
}
2017-01-25 20:13:26 +00:00
fmt.Println(p.GetPassword(door))
2017-01-25 17:58:37 +00:00
}