go-arbitrary/t_password.go

105 lines
2.1 KiB
Go
Raw Normal View History

2021-11-22 19:50:54 +00:00
package arbitrary
2021-11-22 23:40:19 +00:00
import (
"strings"
)
2021-11-22 19:50:54 +00:00
// Password returns an arbitrary password.
func (arb T) Password() string {
var result string
{
result = passwords[arb.randomness.Intn(len(passwords))]
}
2021-11-22 23:40:19 +00:00
if 0 == arb.randomness.Intn(7) {
2021-11-23 00:07:34 +00:00
var words []string = languages[arb.randomness.Intn(len(languages))]
2021-11-22 23:40:19 +00:00
var storage strings.Builder
var limit int = 2 + arb.randomness.Intn(6)
for i:=0; i<limit; i++ {
if 0 != i {
storage.WriteRune(' ')
}
var s string = words[arb.randomness.Intn(len(words))]
2021-11-22 23:56:38 +00:00
if 0 == arb.randomness.Intn(4) {
s = strings.ToUpper(s)
}
if 0 == arb.randomness.Intn(4) {
s = strings.ToTitle(s)
}
2021-11-22 23:40:19 +00:00
storage.WriteString(s)
}
result = storage.String()
}
2021-11-22 19:50:54 +00:00
if 0 == arb.randomness.Intn(97) {
result = arb.String()
}
2021-11-22 23:56:38 +00:00
if 0 == arb.randomness.Intn(2) {
if 0 == arb.randomness.Intn(4) {
result = strings.Replace(result, " ", ".", 1)
}
if 0 == arb.randomness.Intn(2) {
result = strings.ReplaceAll(result, " ", "_")
}
}
if 0 == arb.randomness.Intn(2) {
if 0 == arb.randomness.Intn(2) {
result = strings.Replace(result, "A", "4", 1)
}
if 0 == arb.randomness.Intn(2) {
result = strings.Replace(result, "a", "4", 1)
}
if 0 == arb.randomness.Intn(2) {
result = strings.Replace(result, "E", "3", 1)
}
if 0 == arb.randomness.Intn(2) {
result = strings.Replace(result, "e", "3", 1)
}
if 0 == arb.randomness.Intn(2) {
result = strings.Replace(result, "G", "9", 1)
}
if 0 == arb.randomness.Intn(2) {
result = strings.Replace(result, "g", "9", 1)
}
if 0 == arb.randomness.Intn(2) {
result = strings.Replace(result, "I", "1", 1)
}
if 0 == arb.randomness.Intn(2) {
result = strings.Replace(result, "i", "1", 1)
}
if 0 == arb.randomness.Intn(2) {
result = strings.Replace(result, "O", "0", 1)
}
if 0 == arb.randomness.Intn(2) {
result = strings.Replace(result, "o", "0", 1)
}
if 0 == arb.randomness.Intn(2) {
result = strings.Replace(result, "S", "$", 1)
}
if 0 == arb.randomness.Intn(2) {
result = strings.Replace(result, "s", "$", 1)
}
}
2021-11-22 19:50:54 +00:00
return result
}