gaspass/main.go

82 lines
2.4 KiB
Go
Raw Normal View History

2019-06-05 22:58:03 +03:00
package main
import (
"fmt"
2019-07-05 21:10:12 +03:00
"github.com/KawaiDesu/gaspass/gaspass-core"
2019-06-05 22:58:03 +03:00
"github.com/chzyer/readline"
2019-07-05 21:10:12 +03:00
"github.com/jessevdk/go-flags"
2019-06-05 22:58:03 +03:00
"os"
)
type Resource struct {
PassLen int
Serial int
Host string
}
func checkOpts() bool {
return true
}
func processFlags() {
_, err := flags.Parse(&opts)
if flags.WroteHelp(err) {
os.Exit(1)
}
2019-06-06 01:13:18 +03:00
if ! opts.CharsLower && ! opts.CharsUpper && ! opts.CharsNumbers && ! opts.CharsSpecials {
opts.CharsLower, opts.CharsUpper, opts.CharsNumbers, opts.CharsSpecials = true, true, true, true
}
2019-06-05 22:58:03 +03:00
}
var (
opts struct {
CharsLower bool `short:"l" long:"lower" description:"Use lower-case characters for generating password"`
CharsUpper bool `short:"u" long:"upper" description:"Use upper-case characters for generating password"`
CharsNumbers bool `short:"n" long:"numeric" description:"Use numeric characters for generating password"`
CharsSpecials bool `short:"s" long:"specials" description:"Use speacial (punctuation) characters for generating password"`
Length uint32 `short:"q" long:"quantity" default:"16" description:"Set number of characters in the password"`
2019-06-05 22:58:03 +03:00
Salt string `short:"r" long:"resource" description:"Resource name (url or some descriptive text) for which password will be generated"`
Counter string `short:"c" long:"counter" default:"0" description:"Serial number of the password for the same resource"`
/* // Not implemented yet
2019-06-05 22:58:03 +03:00
ActionAdd bool `short:"A" long:"add" description:"Add resource record to the database"`
ActionRemove bool `short:"D" long:"delete" description:"Remove resource record from the database"`
ActionUseRes bool `short:"R" long:"use-resource" description:"Use existing resource"`
ActionList bool `short:"L" long:"list" description:"List resource records in the database"`
ActionBench bool `short:"B" long:"bench" description:"Run benchmark"`
*/
2019-06-05 22:58:03 +03:00
}
)
func main() {
processFlags()
privKey, err := readline.Password("Enter your key:")
if err != nil {
println(err.Error())
os.Exit(1)
}
2019-06-05 22:58:03 +03:00
p := gaspass.Params{
PrivKey: privKey,
Salt: []byte(opts.Salt),
Counter: []byte(opts.Counter),
PassLength: opts.Length,
UseLower: opts.CharsLower,
UseUpper: opts.CharsUpper,
UseNumbers: opts.CharsNumbers,
2019-06-05 22:58:03 +03:00
UseSpecials: opts.CharsSpecials,
}
resultPass, err := p.GeneratePassword()
if err != nil {
println(err.Error())
os.Exit(1)
}
fmt.Println(*resultPass)
2019-06-05 22:58:03 +03:00
}