-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
52 lines (42 loc) · 996 Bytes
/
config.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
46
47
48
49
50
51
52
package password
import (
"golang.org/x/crypto/bcrypt"
auth "github.com/fmitra/authenticator"
)
const (
defaultCost = bcrypt.DefaultCost
defaultMinLength = 8
defaultMaxLength = 1000
)
// NewPassword returns a new password validator.
func NewPassword(options ...ConfigOption) auth.PasswordService {
s := Password{
cost: defaultCost,
minLength: defaultMinLength,
maxLength: defaultMaxLength,
}
for _, opt := range options {
opt(&s)
}
return &s
}
// ConfigOption configures the validator.
type ConfigOption func(*Password)
// WithCost configures the service with a cost.
func WithCost(cost int) ConfigOption {
return func(s *Password) {
s.cost = cost
}
}
// WithMinLength sets a minimum password length.
func WithMinLength(length int) ConfigOption {
return func(s *Password) {
s.minLength = length
}
}
// WithMaxLength sets a maximum password length.
func WithMaxLength(length int) ConfigOption {
return func(s *Password) {
s.maxLength = length
}
}