2019-01-24 16:26:36 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-29 16:23:44 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-01-15 13:03:24 +00:00
|
|
|
package console
|
2018-11-29 16:23:44 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2022-09-06 21:55:15 +01:00
|
|
|
// PasswordMinimumLength is the minimum allowed length for user account passwords.
|
|
|
|
PasswordMinimumLength = 6
|
|
|
|
// PasswordMaximumLength is the maximum allowed length for user account passwords.
|
2023-02-03 13:48:11 +00:00
|
|
|
PasswordMaximumLength = 72
|
2018-11-29 16:23:44 +00:00
|
|
|
)
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// ErrValidation validation related error class.
|
2021-04-28 09:06:17 +01:00
|
|
|
var ErrValidation = errs.Class("validation")
|
2018-11-29 16:23:44 +00:00
|
|
|
|
2023-02-03 13:48:11 +00:00
|
|
|
// ValidateNewPassword validates password for creation.
|
2022-02-23 16:02:45 +00:00
|
|
|
// It returns an plain error (not wrapped in a errs.Class) if pass is invalid.
|
2023-02-03 13:48:11 +00:00
|
|
|
//
|
|
|
|
// 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 {
|
2022-09-06 21:55:15 +01:00
|
|
|
if len(pass) < PasswordMinimumLength {
|
|
|
|
return errs.New(passwordTooShortErrMsg, PasswordMinimumLength)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(pass) > PasswordMaximumLength {
|
|
|
|
return errs.New(passwordTooLongErrMsg, PasswordMaximumLength)
|
2018-12-10 15:57:06 +00:00
|
|
|
}
|
|
|
|
|
2022-02-23 16:02:45 +00:00
|
|
|
return nil
|
2018-12-10 15:57:06 +00:00
|
|
|
}
|
2019-10-29 14:24:16 +00:00
|
|
|
|
2019-11-25 21:36:36 +00:00
|
|
|
// ValidateFullName validates full name.
|
2022-02-23 16:02:45 +00:00
|
|
|
// It returns an plain error (not wrapped in a errs.Class) if name is invalid.
|
2019-11-25 21:36:36 +00:00
|
|
|
func ValidateFullName(name string) error {
|
2019-10-29 14:24:16 +00:00
|
|
|
if name == "" {
|
|
|
|
return errs.New("full name can not be empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|