mirror of
https://github.com/bytedream/docker4ssh.git
synced 2025-06-27 09:50:31 +02:00
Initial commit
This commit is contained in:
27
server/utils/convert.go
Normal file
27
server/utils/convert.go
Normal file
@ -0,0 +1,27 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func UsernameToRegex(username string) (*regexp.Regexp, error) {
|
||||
var rawUsername string
|
||||
if rawUsername = strings.TrimPrefix(username, "regex:"); rawUsername == username {
|
||||
rawUsername = strings.ReplaceAll(rawUsername, "*", ".*")
|
||||
}
|
||||
return regexp.Compile(rawUsername)
|
||||
}
|
||||
|
||||
func PasswordToRegex(password string) (*regexp.Regexp, error) {
|
||||
splitPassword := strings.SplitN(password, ":", 1)
|
||||
if len(splitPassword) > 1 {
|
||||
switch splitPassword[0] {
|
||||
case "regex":
|
||||
return regexp.Compile(splitPassword[1])
|
||||
case "sha1", "sha256", "sha512":
|
||||
password = splitPassword[1]
|
||||
}
|
||||
}
|
||||
return regexp.Compile(strings.ReplaceAll(password, "*", ".*"))
|
||||
}
|
Reference in New Issue
Block a user