diff --git a/auth/common.go b/auth/common.go index c9a37eccab18bc1bd1be9661cba91183037e93ad..622e0bb614a4062abe82189c10bc33838ccfc5af 100644 --- a/auth/common.go +++ b/auth/common.go @@ -1,8 +1,10 @@ package auth import ( + "fmt" "gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/handler_utils" "golang.org/x/crypto/bcrypt" + "math/rand" "strings" ) @@ -30,3 +32,25 @@ func PasswordIsCorrect(password string, hashedPassword string) bool { err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password)) return err == nil } + +// Create a pseudorandom password consisting of two three-letter words and two digits +func RandomPassword() string { + i := rand.Intn(100) + var j int + for { + j = rand.Intn(100) + if j != i { + break + } + } + return fmt.Sprintf("%s%s%s", words[i], words[j], RandomDigitString(2)) +} + +// Create a pseudorandom string of digits (0-9) with specified length +func RandomDigitString(len int) string { + var str strings.Builder + for i := 0; i < len; i++ { + fmt.Fprintf(&str, "%v", rand.Intn(10)) + } + return str.String() +} diff --git a/auth/words.go b/auth/words.go new file mode 100644 index 0000000000000000000000000000000000000000..fc9c7985c103f7bdfd4e8c692d9349f462bdf97e --- /dev/null +++ b/auth/words.go @@ -0,0 +1,104 @@ +package auth + +var words = []string{ + "act", + "add", + "age", + "air", + "ant", + "ark", + "arm", + "art", + "ash", + "bad", + "bag", + "bar", + "bat", + "bay", + "bed", + "bee", + "big", + "box", + "bus", + "bye", + "can", + "car", + "cat", + "con", + "cow", + "cup", + "day", + "dog", + "ear", + "end", + "eye", + "far", + "fly", + "fox", + "fry", + "fun", + "gap", + "gym", + "hat", + "hip", + "hop", + "ice", + "ink", + "jam", + "jar", + "joy", + "key", + "kit", + "lab", + "law", + "log", + "low", + "man", + "max", + "may", + "net", + "nut", + "oil", + "one", + "out", + "owl", + "own", + "pen", + "pet", + "pie", + "pig", + "pin", + "pro", + "ram", + "rap", + "ray", + "red", + "row", + "sea", + "see", + "sew", + "sit", + "six", + "sky", + "son", + "spy", + "tan", + "tax", + "tea", + "ted", + "tee", + "ten", + "the", + "tin", + "toe", + "top", + "toy", + "tub", + "two", + "way", + "wig", + "yes", + "you", + "zip", + "zoo", +}