Require at least one non-numeric character in usernames

This commit is contained in:
Trevor Slocum 2023-09-09 00:40:29 -07:00
parent 16fce188d3
commit dcf67d62c3

View file

@ -6,6 +6,7 @@ import (
"log"
"math/rand"
"net"
"regexp"
"strconv"
"strings"
"sync"
@ -16,6 +17,8 @@ import (
const clientTimeout = 10 * time.Minute
var onlyNumbers = regexp.MustCompile(`^[0-9]+$`)
type serverCommand struct {
client *serverClient
command []byte
@ -275,7 +278,10 @@ COMMANDS:
var password []byte
readUsername := func() bool {
username = params[0]
if !s.nameAvailable(username) {
if onlyNumbers.Match(username) {
cmd.client.Terminate("Invalid username: must contain at least one non-numeric character.")
return false
} else if !s.nameAvailable(username) {
cmd.client.Terminate("Username unavailable.")
return false
}