53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"code.google.com/p/gopass"
|
|
"flag"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
var siteName string
|
|
|
|
const DEFAULT_SITE = "etrade"
|
|
|
|
func init() {
|
|
const site_usage = "Name of site for which to generate password"
|
|
flag.StringVar(&siteName, "siteName", DEFAULT_SITE, site_usage)
|
|
flag.StringVar(&siteName, "s", DEFAULT_SITE, site_usage+" (shorthand)")
|
|
}
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
var restrictions *PasswordRestrictions
|
|
for _, v := range sites {
|
|
if strings.ToLower(siteName) == strings.ToLower(v.name) {
|
|
restrictions = &v
|
|
break
|
|
}
|
|
}
|
|
|
|
if restrictions == nil {
|
|
fmt.Println("Error: Site name not recognized, please use one of the following:")
|
|
for _, v := range sites {
|
|
fmt.Println("\t" + v.name)
|
|
}
|
|
return
|
|
}
|
|
|
|
oldPassword, err := gopass.GetPass("Enter Password: ")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
pw := NewPassword(restrictions, oldPassword)
|
|
pw.InitialRandom()
|
|
pw.FixupMinimumRequirements()
|
|
pw.FixupAdditionalRequirements()
|
|
pw.RandomizeOrder()
|
|
pw.FixupAdditionalRequirements() //run this again, since randomizing the order can potentially introduce things which don't meet the additional requirements if they rely on not having duplicate characters next to each other, etc.
|
|
|
|
fmt.Println("Generated password for " + restrictions.name + ": " + pw.password)
|
|
}
|