storj/satellite/console/validation.go
Egon Elbre 873a202530 mod: bump storj.io/common
This bumps common, such that things build with Go 1.20.

Also, adds `go vet` checks for testsuite/storjscan and testsuite/ui.

The latest golang.org/x/bcrypt has a check that the new password is less
than 72 bytes, because bcrypt silently discarded them. This means our
own password validation has the same limitation. Old passwords should
still work fine.

Change-Id: Ibb8735b15eeb91460145906b81ae4e365e9ac418
2023-02-03 16:49:41 +02:00

46 lines
1.2 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 = 72
)
// ErrValidation validation related error class.
var ErrValidation = errs.Class("validation")
// ValidateNewPassword validates password for creation.
// It returns an plain error (not wrapped in a errs.Class) if pass is invalid.
//
// Previously the limit was 128, however, bcrypt ignores any characters beyond 72,
// hence this checks new passwords -- old passwords might be longer.
func ValidateNewPassword(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
}