Esempio n. 1
0
File: main.go Progetto: r2p2/pwmake
// generate the password,
// This will generate a password with the given specifications, and return it.
// Any error from the password generator will be relayed here and can be printed
// to the user.
func GeneratePassword() (string, error) {
	var gen *pwdgen.PwdGen
	var symset *symbol.MultiSet
	var err error

	if symset, err = symbol.NewMultiSetFromDefaults([]string{"alpha", "ALPHA", "num"}); err != nil {
		return "", err
	}

	if gen, err = pwdgen.NewPwdGen(symset, cmdline.PwLength); err != nil {
		return "", err
	}
	return gen.String(), nil
}
Esempio n. 2
0
func BenchmarkPwdGenString(b *testing.B) {
	length := 10
	b.StopTimer()
	var gen *PwdGen
	var symset *symbol.MultiSet
	var err error

	if symset, err = symbol.NewMultiSetFromDefaults([]string{"alpha", "ALPHA", "num"}); err != nil {
		b.Fatalf("Unable to create default MultiSet: %s", err)
	}

	if gen, err = NewPwdGen(symset, length); err != nil {
		b.Fatalf("Unable to create generator: %s", err)
	}
	b.StartTimer()

	for i := 0; i < b.N; i++ {
		if s := gen.String(); len(s) != length {
			b.Errorf("generated password \"%s\" does not have the expected length of %d", s, length)
		}
	}
}