2023-06-28 17:51:36 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/tjarratt/babble"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Passphrase string
|
|
|
|
|
|
|
|
func NewPassphrase() Passphrase {
|
|
|
|
var phrase string
|
|
|
|
var retries int
|
|
|
|
var word string
|
2023-06-29 20:20:41 +00:00
|
|
|
var words int = 2
|
2023-07-05 19:15:01 +00:00
|
|
|
//TODO make sure passphrases are unique
|
2023-06-28 17:51:36 +00:00
|
|
|
for words > 0 {
|
|
|
|
retries = 20
|
|
|
|
for {
|
|
|
|
word = getCleanWord()
|
|
|
|
if isAccecpable(word) {
|
|
|
|
phrase = phrase + word + " "
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if retries == 1 { //this is our last try, we take any word
|
|
|
|
phrase = phrase + word + " "
|
|
|
|
}
|
|
|
|
retries -= 1
|
|
|
|
}
|
|
|
|
words -= 1
|
|
|
|
}
|
|
|
|
return Passphrase(strings.TrimSpace(phrase))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p Passphrase) String() string {
|
|
|
|
return string(p)
|
|
|
|
}
|
|
|
|
|
|
|
|
func isAccecpable(s string) bool {
|
|
|
|
l := len(s)
|
|
|
|
if l > 8 || l < 3 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, rune := range s {
|
|
|
|
if !isEnglishLetter(rune) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func isProfanity(s string) bool {
|
|
|
|
contains := []string{
|
|
|
|
"nigg",
|
2023-06-29 20:20:41 +00:00
|
|
|
"fag",
|
2023-07-05 19:15:01 +00:00
|
|
|
"ass",
|
|
|
|
"bitch",
|
2023-07-06 12:57:35 +00:00
|
|
|
"rape",
|
|
|
|
"ass",
|
|
|
|
"scrot",
|
|
|
|
"rect",
|
2023-06-28 17:51:36 +00:00
|
|
|
}
|
|
|
|
startsWith := []string{
|
|
|
|
"spic",
|
|
|
|
"chin",
|
|
|
|
"cunt",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, word := range contains {
|
|
|
|
if strings.Contains(s, word) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, word := range startsWith {
|
|
|
|
if strings.HasPrefix(s, word) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func isEnglishLetter(r rune) bool {
|
|
|
|
if (r < 'a' || r > 'z') && (r < 'A' || r > 'Z') {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func getCleanWord() string {
|
|
|
|
var word string
|
|
|
|
|
|
|
|
babbler := babble.NewBabbler()
|
|
|
|
babbler.Count = 1
|
|
|
|
|
|
|
|
for {
|
|
|
|
word = babbler.Babble()
|
|
|
|
if !isProfanity(word) {
|
|
|
|
return word
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|