Exemplo n.º 1
0
func (s *PassgenSuite) TestNoLengthError(c *C) {
	g := passgen.New()
	abc := g.AddAlphabet("abc")
	abc.SetMinMax(0, 100)
	_, err := g.Generate()
	c.Assert(err, NotNil)
}
Exemplo n.º 2
0
func (s *PassgenSuite) TestExclude(c *C) {
	g := passgen.New()
	g.SetLength(100, 100)
	g.AddAlphabet("abc")
	g.Exclude = "bc"
	p, _ := g.Generate()
	c.Assert(p, Matches, "a{100}")
}
Exemplo n.º 3
0
func (s *PassgenSuite) TestMaxError(c *C) {
	g := passgen.New()
	g.SetLength(10, 10)
	abc := g.AddAlphabet("abc")
	abc.SetMax(1)
	_, err := g.Generate()
	c.Assert(err, NotNil)
}
Exemplo n.º 4
0
func (s *PassgenSuite) TestMultiCharGenerate(c *C) {
	g := passgen.New()
	g.SetLength(10, 20)
	abc := g.AddAlphabet("abc")
	abc.SetMinMax(0, 100)
	p, _ := g.Generate()
	c.Assert(p, Matches, "[abc]{10,20}")
}
Exemplo n.º 5
0
func (s *PassgenSuite) TestSingleCharGenerate(c *C) {
	g := passgen.New()
	g.SetLength(5, 5)
	g.AddAlphabet("a")
	p, _ := g.Generate()
	c.Assert(len(p), Equals, 5)
	c.Assert(p, Equals, "aaaaa")
}
Exemplo n.º 6
0
func (s *PassgenSuite) TestImpossibleConstraint(c *C) {
	g := passgen.New()
	g.SetLength(10, 10)
	a := g.AddAlphabet("a")
	a.SetMinMax(6, 10)
	b := g.AddAlphabet("b")
	b.SetMinMax(6, 10)
	_, err := g.Generate()
	c.Assert(err, NotNil)
}
Exemplo n.º 7
0
func (s *PassgenSuite) TestMultiAlphabet(c *C) {
	g := passgen.New()
	g.SetLength(8, 8)
	a := g.AddAlphabet("a")
	a.SetMinMax(3, 3)
	b := g.AddAlphabet("b")
	b.SetMinMax(5, 5)
	p, _ := g.Generate()
	c.Assert(strings.Replace(p, "b", "", -1), Equals, "aaa")
	c.Assert(strings.Replace(p, "a", "", -1), Equals, "bbbbb")
}
Exemplo n.º 8
0
func (s *PassgenSuite) TestEmptyError(c *C) {
	g := passgen.New()
	_, err := g.Generate()
	c.Assert(err, NotNil)
}
Exemplo n.º 9
0
func (s *PassgenSuite) TestNew(c *C) {
	g := passgen.New()
	c.Assert(g, NotNil)
}
Exemplo n.º 10
0
Arquivo: add.go Projeto: schmich/ward
func (app *App) addCommand(cmd *cli.Cmd) {
	const SimilarChars = "5SB8|1IiLl0Oo"

	cmd.Spec = "[--login] [--realm] [--note] [--no-copy] [--gen [--length] [--min-length] [--max-length] [--no-upper] [--no-lower] [--no-digit] [--no-symbol] [--no-similar] [--min-upper] [--max-upper] [--min-lower] [--max-lower] [--min-digit] [--max-digit] [--min-symbol] [--max-symbol] [--exclude]]"

	login := cmd.StringOpt("login", "", "Login for credential, e.g. username or email.")
	realm := cmd.StringOpt("realm", "", "Realm for credential, e.g. website or WiFi AP name.")
	note := cmd.StringOpt("note", "", "Note for credential.")
	noCopy := cmd.BoolOpt("no-copy", false, "Do not copy password to the clipboard.")

	gen := cmd.BoolOpt("gen", false, "Generate a password.")
	length := cmd.IntOpt("length", 0, "Password length.")
	minLength := cmd.IntOpt("min-length", 30, "Minimum length password.")
	maxLength := cmd.IntOpt("max-length", 40, "Maximum length password.")

	noUpper := cmd.BoolOpt("no-upper", false, "Exclude uppercase characters from password.")
	noLower := cmd.BoolOpt("no-lower", false, "Exclude lowercase characters from password.")
	noDigit := cmd.BoolOpt("no-digit", false, "Exclude digit characters from password.")
	noSymbol := cmd.BoolOpt("no-symbol", false, "Exclude symbol characters from password.")
	noSimilar := cmd.BoolOpt("no-similar", false, "Exclude similar characters from password: "******".")

	minUpper := cmd.IntOpt("min-upper", 0, "Minimum number of uppercase characters in password.")
	maxUpper := cmd.IntOpt("max-upper", -1, "Maximum number of uppercase characters in password.")
	minLower := cmd.IntOpt("min-lower", 0, "Minimum number of lowercase characters in password.")
	maxLower := cmd.IntOpt("max-lower", -1, "Maximum number of lowercase characters in password.")
	minDigit := cmd.IntOpt("min-digit", 0, "Minimum number of digit characters in password.")
	maxDigit := cmd.IntOpt("max-digit", -1, "Maximum number of digit characters in password.")
	minSymbol := cmd.IntOpt("min-symbol", 0, "Minimum number of symbol characters in password.")
	maxSymbol := cmd.IntOpt("max-symbol", -1, "Maximum number of symbol characters in password.")

	exclude := cmd.StringOpt("exclude", "", "Exclude specific characters from password.")

	cmd.Action = func() {
		if !*gen {
			app.runAdd(*login, *realm, *note, !*noCopy)
		} else {
			generator := passgen.New()
			if *length == 0 {
				generator.SetLength(*minLength, *maxLength)
			} else {
				generator.SetLength(*length, *length)
			}
			upper := generator.AddAlphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
			lower := generator.AddAlphabet("abcdefghijklmnopqrstuvwxyz")
			digit := generator.AddAlphabet("0123456789")
			symbol := generator.AddAlphabet("`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?")
			upper.SetMinMax(*minUpper, *maxUpper)
			lower.SetMinMax(*minLower, *maxLower)
			digit.SetMinMax(*minDigit, *maxDigit)
			symbol.SetMinMax(*minSymbol, *maxSymbol)
			if *noUpper {
				upper.SetMinMax(0, 0)
			}
			if *noLower {
				lower.SetMinMax(0, 0)
			}
			if *noDigit {
				digit.SetMinMax(0, 0)
			}
			if *noSymbol {
				symbol.SetMinMax(0, 0)
			}
			generator.Exclude = *exclude
			if *noSimilar {
				generator.Exclude += SimilarChars
			}
			app.runGen(*login, *realm, *note, !*noCopy, generator)
		}
	}
}