Skip to content

Commit 574b9d2

Browse files
committed
Use canonical error value for unchanged password errors
1 parent c9dcf91 commit 574b9d2

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

credential.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (c *Credential) ChangePasswordWithConfigAndIP(config Config, oldPassword, n
118118
return errors.New("Old password does not match existing password")
119119
}
120120
if subtle.ConstantTimeCompare([]byte(oldPassword), []byte(newPassword)) == 1 {
121-
return errors.New("Password unchanged")
121+
return ErrPasswordUnchanged
122122
}
123123
return c.ResetWithConfigAndIP(config, newPassword, ip)
124124
}

errors.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package passhash
2+
3+
import (
4+
"errors"
5+
)
6+
7+
var (
8+
// ErrPasswordUnchanged is used when a Credential.ChangePassword*() method is called with the same old and new
9+
// password
10+
ErrPasswordUnchanged = errors.New("Password unchanged")
11+
)

0 commit comments

Comments
 (0)