-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patherrors.go
36 lines (30 loc) · 1002 Bytes
/
errors.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
package passhash
import (
"errors"
"fmt"
"strings"
)
var (
// ErrPasswordUnchanged is used when a Credential.ChangePassword*() method is called with the same old and new
// password
ErrPasswordUnchanged = errors.New("Password unchanged")
)
// PasswordPolicyError satisfies the error interface and describes the reason for a PasswordPolicy check failure
type PasswordPolicyError struct {
PasswordPolicy PasswordPolicy
Err error
}
func (e PasswordPolicyError) Error() string {
return e.Err.Error()
}
// PasswordPoliciesNotMet satisfies the error interface and tracks the unmet password policies
type PasswordPoliciesNotMet struct {
UnMetPasswordPolicies []PasswordPolicyError
}
func (e PasswordPoliciesNotMet) Error() string {
errorStrs := make([]string, 0, len(e.UnMetPasswordPolicies))
for _, ppe := range e.UnMetPasswordPolicies {
errorStrs = append(errorStrs, ppe.Error())
}
return fmt.Sprintf("Password policies not met due to: %s", strings.Join(errorStrs, ", "))
}