storj/satellite/console/validation.go
Jeremy Wharton 92d81db183 satellite/console,web/satellite: limit new password length to 128
This change implements a requirement that all new passwords must be
no longer than 128 characters.

Change-Id: I7a8f23c87190d465eed59b3e0627ccd32d465bb9
2022-09-08 13:29:47 +00:00

43 lines
1.1 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package console
import (
"github.com/zeebo/errs"
)
const (
// PasswordMinimumLength is the minimum allowed length for user account passwords.
PasswordMinimumLength = 6
// PasswordMaximumLength is the maximum allowed length for user account passwords.
PasswordMaximumLength = 128
)
// ErrValidation validation related error class.
var ErrValidation = errs.Class("validation")
// ValidatePassword validates password.
// It returns an plain error (not wrapped in a errs.Class) if pass is invalid.
func ValidatePassword(pass string) error {
if len(pass) < PasswordMinimumLength {
return errs.New(passwordTooShortErrMsg, PasswordMinimumLength)
}
if len(pass) > PasswordMaximumLength {
return errs.New(passwordTooLongErrMsg, PasswordMaximumLength)
}
return nil
}
// ValidateFullName validates full name.
// It returns an plain error (not wrapped in a errs.Class) if name is invalid.
func ValidateFullName(name string) error {
if name == "" {
return errs.New("full name can not be empty")
}
return nil
}