From caa80fd73bf3283d696130977ed07e3868df1a30 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 7 Oct 2023 09:36:54 -0400 Subject: [PATCH] more --- main_test.go | 1 + password.go | 25 ++++++++++++------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/main_test.go b/main_test.go index 25708ee..791f03f 100644 --- a/main_test.go +++ b/main_test.go @@ -13,6 +13,7 @@ import ( func TestUsers(t *testing.T) { var email string c.testing = true + generatePassword(16) flag.StringVar(&email, "email", "", "Email address to use for registration test") flag.Parse() diff --git a/password.go b/password.go index 84a04b2..ea9afd4 100644 --- a/password.go +++ b/password.go @@ -3,28 +3,27 @@ package scsusers import ( "crypto/rand" "encoding/base32" + "log" mr "math/rand" "time" "unicode" ) func flipCoin() bool { - r:=mr.New(mr.NewSource(time.Now().Unix())) - return r.Intn(2)==1 - + r := mr.New(mr.NewSource(time.Now().UnixNano())) + return r.Intn(3) == 1 } + func scrambleCase(in []byte) []byte { var out []byte for _, x := range string(in) { - if unicode.IsUpper(x) { - if flipCoin() { - out = append(out, byte(x)) - } else { - out = append(out, byte(unicode.ToLower(x))) - - } + if unicode.IsUpper(x) && flipCoin() { + out = append(out, byte(unicode.ToLower(x))) + } else { + out = append(out, byte(x)) } } + log.Printf("scrambleCase in %s out %s", in, out) return out } @@ -48,7 +47,7 @@ func generatePassword(n int) []byte { } func hasDigit(in []byte) bool { - for _,x := range string(in) { + for _, x := range string(in) { if unicode.IsDigit(x) { return true } @@ -57,7 +56,7 @@ func hasDigit(in []byte) bool { } func hasUppercase(in []byte) bool { - for _,x:= range string(in) { + for _, x := range string(in) { if unicode.IsUpper(x) { return true } @@ -66,7 +65,7 @@ func hasUppercase(in []byte) bool { } func hasLowercase(in []byte) bool { - for _,x := range string(in) { + for _, x := range string(in) { if unicode.IsLower(x) { return true }