-
Notifications
You must be signed in to change notification settings - Fork 402
/
validation.go
45 lines (36 loc) · 1.44 KB
/
validation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// 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, based on NIST guidelines for user-generated passwords.
PasswordMinimumLength = 8
// PasswordMaximumLength is the maximum allowed length for user account passwords, based on NIST guidelines for user-generated passwords.
PasswordMaximumLength = 64
)
// 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.
//
// Password minimum length has previously been as short as 6, and maximum as long as 128.
// Therefore, this validation should only be applied to new passwords - old passwords may have previously been created outside of the 8-64 length range.
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
}