Skip to content

Commit 9720dc2

Browse files
committed
Unexport Credential methods
1 parent dba2caf commit 9720dc2

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

server/auth.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ func scrambleValidation(cached, nonce, scramble []byte) bool {
6767

6868
func (c *Conn) compareNativePasswordAuthData(clientAuthData []byte, credential Credential) error {
6969
if len(clientAuthData) == 0 {
70-
if credential.HasEmptyPassword() {
70+
if credential.hasEmptyPassword() {
7171
return nil
7272
}
7373
return ErrAccessDeniedNoPassword
7474
}
7575

7676
for _, password := range credential.Passwords {
77-
hash, err := credential.HashPassword(password)
77+
hash, err := credential.hashPassword(password)
7878
if err != nil {
7979
continue
8080
}
@@ -92,7 +92,7 @@ func (c *Conn) compareNativePasswordAuthData(clientAuthData []byte, credential C
9292
func (c *Conn) compareSha256PasswordAuthData(clientAuthData []byte, credential Credential) error {
9393
// Empty passwords are not hashed, but sent as empty string
9494
if len(clientAuthData) == 0 {
95-
if credential.HasEmptyPassword() {
95+
if credential.hasEmptyPassword() {
9696
return nil
9797
}
9898
return ErrAccessDeniedNoPassword
@@ -119,7 +119,7 @@ func (c *Conn) compareSha256PasswordAuthData(clientAuthData []byte, credential C
119119
}
120120
}
121121
for _, password := range credential.Passwords {
122-
hash, err := credential.HashPassword(password)
122+
hash, err := credential.hashPassword(password)
123123
if err != nil {
124124
continue
125125
}
@@ -137,7 +137,7 @@ func (c *Conn) compareSha256PasswordAuthData(clientAuthData []byte, credential C
137137
func (c *Conn) compareCacheSha2PasswordAuthData(clientAuthData []byte) error {
138138
// Empty passwords are not hashed, but sent as empty string
139139
if len(clientAuthData) == 0 {
140-
if c.credential.HasEmptyPassword() {
140+
if c.credential.hasEmptyPassword() {
141141
return nil
142142
}
143143
return ErrAccessDeniedNoPassword

server/auth_switch_response.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ func (c *Conn) handleCachingSha2PasswordFullAuth(authData []byte) error {
7272

7373
func (c *Conn) checkSha2CacheCredentials(clientAuthData []byte, credential Credential) error {
7474
if len(clientAuthData) == 0 {
75-
if credential.HasEmptyPassword() {
75+
if credential.hasEmptyPassword() {
7676
return nil
7777
}
7878
return ErrAccessDeniedNoPassword
7979
}
8080

8181
for _, password := range credential.Passwords {
82-
hash, err := credential.HashPassword(password)
82+
hash, err := credential.hashPassword(password)
8383
if err != nil {
8484
continue
8585
}

server/authentication_handler.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import (
1616
// if the password in a third-party auth handler could be updated at runtime, we have to invalidate the caching
1717
// for 'caching_sha2_password' by calling 'func (s *Server)InvalidateCache(string, string)'.
1818
type AuthenticationHandler interface {
19-
// get user credential (supports multiple valid passwords per user)
19+
// GetCredential returns the user credential (supports multiple valid passwords per user).
20+
// Implementations must be safe for concurrent use.
2021
GetCredential(username string) (credential Credential, found bool, err error)
2122

2223
// OnAuthSuccess is called after successful authentication, before the OK packet.
@@ -45,8 +46,8 @@ type Credential struct {
4546
AuthPluginName string
4647
}
4748

48-
// HashPassword computes the password hash for a given password using the credential's auth plugin.
49-
func (c Credential) HashPassword(password string) (string, error) {
49+
// hashPassword computes the password hash for a given password using the credential's auth plugin.
50+
func (c Credential) hashPassword(password string) (string, error) {
5051
if password == "" {
5152
return "", nil
5253
}
@@ -69,8 +70,8 @@ func (c Credential) HashPassword(password string) (string, error) {
6970
}
7071
}
7172

72-
// HasEmptyPassword returns true if any password in the credential is empty.
73-
func (c Credential) HasEmptyPassword() bool {
73+
// hasEmptyPassword returns true if any password in the credential is empty.
74+
func (c Credential) hasEmptyPassword() bool {
7475
return slices.Contains(c.Passwords, "")
7576
}
7677

0 commit comments

Comments
 (0)