68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/jessevdk/go-flags"
|
|
"r00t2.io/pwgen/pwgenerator"
|
|
)
|
|
|
|
var a Arguments
|
|
|
|
func main() {
|
|
|
|
var err error
|
|
var genOpts *pwgenerator.GenOpts
|
|
var passwds []string
|
|
|
|
if _, err = flags.Parse(&a); err != nil {
|
|
switch flagsErr := err.(type) {
|
|
case *flags.Error:
|
|
if flagsErr.Type == flags.ErrHelp {
|
|
os.Exit(0)
|
|
}
|
|
log.Panicln(err)
|
|
default:
|
|
log.Panicln(err)
|
|
}
|
|
}
|
|
|
|
genOpts = &pwgenerator.GenOpts{
|
|
Alpha: !a.NoAlpha,
|
|
Numeric: !a.NoNum,
|
|
Symbols: !a.NoSymbols,
|
|
ExtendedSymbols: a.ExtendSymbols,
|
|
CountUpper: a.NumUpper,
|
|
CountLower: a.NumLower,
|
|
CountNumbers: a.NumNumbers,
|
|
CountSymbols: a.NumSymbols,
|
|
CountExtended: a.NumExtended,
|
|
DisabledChars: nil,
|
|
LengthMin: a.MinLen,
|
|
LengthMax: a.MaxLen,
|
|
Count: a.Count,
|
|
}
|
|
if a.DisableChars != nil && len(a.DisableChars) != 0 {
|
|
if genOpts.DisabledChars, err = pwgenerator.GetCharset(a.DisableChars); err != nil {
|
|
log.Panicln(err)
|
|
}
|
|
}
|
|
if a.ExplicitChars != nil && len(a.ExplicitChars) != 0 {
|
|
if err = genOpts.SetExplicitCharset(a.ExplicitChars, false); err != nil {
|
|
log.Panicln(err)
|
|
}
|
|
}
|
|
|
|
if passwds, err = genOpts.Generate(); err != nil {
|
|
log.Panicln(err)
|
|
}
|
|
|
|
fmt.Println(strings.Join(passwds, "\n"))
|
|
|
|
// fmt.Printf("%#v\n", a)
|
|
// fmt.Printf("%#v\n", genOpts)
|
|
}
|