Add username check.

This commit is contained in:
Yang Luo
2021-05-01 16:50:47 +08:00
parent 9971b368d0
commit a093f3af5a
2 changed files with 19 additions and 1 deletions

View File

@ -14,11 +14,22 @@
package object
import "fmt"
import (
"fmt"
"regexp"
)
var reWhiteSpace *regexp.Regexp
func init() {
reWhiteSpace, _ = regexp.Compile("\\s")
}
func CheckUserSignup(userId string, password string) string {
if len(userId) == 0 || len(password) == 0 {
return "username and password cannot be blank"
} else if reWhiteSpace.MatchString(userId) {
return "username cannot contain white spaces"
} else if HasUser(userId) {
return "username already exists"
} else {