mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
fix: Add restriction to username when signing up (#1203)
This commit is contained in:
@ -313,3 +313,21 @@ func CheckAccessPermission(userId string, application *Application) (bool, error
|
||||
}
|
||||
return allowed, err
|
||||
}
|
||||
|
||||
func CheckUsername(name string) string {
|
||||
if name == "" {
|
||||
return "Empty username."
|
||||
} else if len(name) > 39 {
|
||||
return "Username is too long (maximum is 39 characters)."
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/58726546/github-username-convention-using-regex
|
||||
re, _ := regexp.Compile("^[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*$")
|
||||
if !re.MatchString(name) {
|
||||
return fmt.Sprintf("The name '%s' may only contain alphanumeric characters or hyphens, "+
|
||||
"cannot have multiple consecutive hyphens, "+
|
||||
"and cannot begin or end with a hyphen.", name)
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
Reference in New Issue
Block a user