1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
package validators
import (
"regexp"
"shrine/utils/collections"
"strings"
)
var validUsernamePattern = regexp.MustCompile(`^[a-zA-Z0-9_]+$`)
var reservedUsernames = collections.SetOf(
"admin", "administrator", "owner",
"mod", "moderator", "janitor", "staff",
"api", "www", "mail", "email",
"support", "help", "helpdesk",
"about", "contact", "privacy", "terms", "tos",
"null", "undefined", "system", "bot", "guest",
"login", "register", "signup", "signin", "logout",
"profile", "settings", "account", "dashboard",
"shifoo", "pagoda", "deleted", "anonymous",
"root", "webmaster", "postmaster", "hostmaster",
"noreply", "no_reply", "mailer", "daemon",
"abuse", "security", "info", "status",
"home", "search", "explore", "discover",
"forums", "forum", "chat", "bazaar", "districts",
"members", "online", "buttons", "webring",
"guestbook", "hitcounter", "letters",
"rules", "faq", "blog", "news", "feed",
"static", "assets", "uploads", "images", "media", "default", "defaults",
"test", "testing", "debug", "dev", "staging",
"everyone", "all", "here", "channel",
)
func IsValidUsername(username string, minimumLength int) bool {
if len(username) < minimumLength || len(username) > 32 {
return false
}
return validUsernamePattern.MatchString(username)
}
func IsReservedUsername(username string) bool {
return reservedUsernames.Has(strings.ToLower(username))
}
|