MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / ValidateName

Function ValidateName

internal/users/users.go:530–559  ·  view source on GitHub ↗
(name string)

Source from the content-addressed store, hash-verified

528}
529
530func ValidateName(name string) error {
531
532 validation := configs.GetValidationConfig()
533
534 if len(name) < int(validation.NameSizeMin) || len(name) > int(validation.NameSizeMax) {
535 return fmt.Errorf("name must be between %d and %d characters long", validation.NameSizeMin, validation.NameSizeMax)
536 }
537
538 if validation.NameRejectRegex != `` {
539 if !regexp.MustCompile(validation.NameRejectRegex.String()).MatchString(name) {
540 return errors.New(validation.NameRejectReason.String())
541 }
542 }
543
544 if bannedPattern, ok := configs.GetConfig().IsBannedName(name); ok {
545 return errors.New(`that username matched the prohibited name pattern: "` + bannedPattern + `"`)
546 }
547
548 for _, mobName := range mobs.GetAllMobNames() {
549 if strings.EqualFold(mobName, name) {
550 return errors.New("that username is in use")
551 }
552 }
553
554 if Exists(name) {
555 return errors.New("that username is in use")
556 }
557
558 return nil
559}
560
561func ValidatePassword(pw string) error {
562

Callers 6

ValidateUsernameFunction · 0.92
StartFunction · 0.92
PetFunction · 0.92
CreateUserFunction · 0.85
SetUsernameMethod · 0.85
SetCharacterNameMethod · 0.85

Calls 7

GetValidationConfigFunction · 0.92
GetConfigFunction · 0.92
GetAllMobNamesFunction · 0.92
NewMethod · 0.80
IsBannedNameMethod · 0.80
ExistsFunction · 0.70
StringMethod · 0.65

Tested by

no test coverage detected