2021-09-19 17:47:50 +02:00
|
|
|
package chars
|
2021-03-21 14:05:14 +01:00
|
|
|
|
2021-03-26 14:27:54 +01:00
|
|
|
import (
|
2021-09-19 17:47:50 +02:00
|
|
|
"github.com/wneessen/apg-go/config"
|
2021-03-26 14:27:54 +01:00
|
|
|
"regexp"
|
|
|
|
)
|
|
|
|
|
|
|
|
const PwLowerCharsHuman string = "abcdefghjkmnpqrstuvwxyz"
|
|
|
|
const PwUpperCharsHuman string = "ABCDEFGHJKMNPQRSTUVWXYZ"
|
|
|
|
const PwLowerChars string = "abcdefghijklmnopqrstuvwxyz"
|
|
|
|
const PwUpperChars string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
const PwSpecialCharsHuman string = "\"#%*+-/:;=\\_|~"
|
|
|
|
const PwSpecialChars string = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
|
|
|
|
const PwNumbersHuman string = "23456789"
|
|
|
|
const PwNumbers string = "1234567890"
|
2021-03-21 14:05:14 +01:00
|
|
|
|
2021-09-19 17:47:50 +02:00
|
|
|
// GetRange provides the range of available characters based on configured parameters
|
|
|
|
func GetRange(config *config.Config) string {
|
2021-03-21 14:05:14 +01:00
|
|
|
pwUpperChars := PwUpperChars
|
|
|
|
pwLowerChars := PwLowerChars
|
|
|
|
pwNumbers := PwNumbers
|
|
|
|
pwSpecialChars := PwSpecialChars
|
2021-09-19 17:47:50 +02:00
|
|
|
if config.HumanReadable {
|
2021-03-21 14:05:14 +01:00
|
|
|
pwUpperChars = PwUpperCharsHuman
|
|
|
|
pwLowerChars = PwLowerCharsHuman
|
|
|
|
pwNumbers = PwNumbersHuman
|
|
|
|
pwSpecialChars = PwSpecialCharsHuman
|
|
|
|
}
|
|
|
|
|
|
|
|
var charRange string
|
2021-09-19 17:47:50 +02:00
|
|
|
if config.UseLowerCase {
|
2021-03-21 14:05:14 +01:00
|
|
|
charRange = charRange + pwLowerChars
|
|
|
|
}
|
2021-09-19 17:47:50 +02:00
|
|
|
if config.UseUpperCase {
|
2021-03-21 14:05:14 +01:00
|
|
|
charRange = charRange + pwUpperChars
|
|
|
|
}
|
2021-09-19 17:47:50 +02:00
|
|
|
if config.UseNumber {
|
2021-03-21 14:05:14 +01:00
|
|
|
charRange = charRange + pwNumbers
|
|
|
|
}
|
2021-09-19 17:47:50 +02:00
|
|
|
if config.UseSpecial {
|
2021-03-21 14:05:14 +01:00
|
|
|
charRange = charRange + pwSpecialChars
|
|
|
|
}
|
2021-09-19 17:47:50 +02:00
|
|
|
if config.ExcludeChars != "" {
|
|
|
|
regExp := regexp.MustCompile("[" + regexp.QuoteMeta(config.ExcludeChars) + "]")
|
2021-03-21 14:05:14 +01:00
|
|
|
charRange = regExp.ReplaceAllLiteralString(charRange, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
return charRange
|
|
|
|
}
|