@@ -45,14 +45,6 @@ func (c *Conn) acquirePassword() error {
4545 return nil
4646}
4747
48- func errAccessDenied (credential Credential ) error {
49- if credential .Password == "" {
50- return ErrAccessDeniedNoPassword
51- }
52-
53- return ErrAccessDenied
54- }
55-
5648func scrambleValidation (cached , nonce , scramble []byte ) bool {
5749 // SHA256(SHA256(SHA256(STORED_PASSWORD)), NONCE)
5850 crypt := sha256 .New ()
@@ -74,14 +66,21 @@ func scrambleValidation(cached, nonce, scramble []byte) bool {
7466}
7567
7668func (c * Conn ) compareNativePasswordAuthData (clientAuthData []byte , credential Credential ) error {
69+ if len (clientAuthData ) == 0 {
70+ if credential .Password == "" {
71+ return nil
72+ }
73+ return ErrAccessDeniedNoPassword
74+ }
75+
7776 password , err := mysql .DecodePasswordHex (c .credential .Password )
7877 if err != nil {
79- return errAccessDenied ( credential )
78+ return ErrAccessDenied
8079 }
8180 if mysql .CompareNativePassword (clientAuthData , password , c .salt ) {
8281 return nil
8382 }
84- return errAccessDenied ( credential )
83+ return ErrAccessDenied
8584}
8685
8786func (c * Conn ) compareSha256PasswordAuthData (clientAuthData []byte , credential Credential ) error {
@@ -141,7 +140,7 @@ func (c *Conn) compareCacheSha2PasswordAuthData(clientAuthData []byte) error {
141140 return c .writeAuthMoreDataFastAuth ()
142141 }
143142
144- return errAccessDenied ( c . credential )
143+ return ErrAccessDenied
145144 }
146145 // cache miss, do full auth
147146 if err := c .writeAuthMoreDataFullAuth (); err != nil {
0 commit comments