@@ -352,7 +352,9 @@ func (mc *mysqlConn) writeAuthPacket(cipher []byte) error {
352
352
// http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchResponse
353
353
func (mc * mysqlConn ) writeOldAuthPacket (cipher []byte ) error {
354
354
// User password
355
- scrambleBuff := scrambleOldPassword (cipher , []byte (mc .cfg .Passwd ))
355
+ // https://dev.mysql.com/doc/internals/en/old-password-authentication.html
356
+ // Old password authentication only need and will need 8-byte challenge.
357
+ scrambleBuff := scrambleOldPassword (cipher [:8 ], []byte (mc .cfg .Passwd ))
356
358
357
359
// Calculate the packet length and add a tailing 0
358
360
pktLen := len (scrambleBuff ) + 1
@@ -392,7 +394,9 @@ func (mc *mysqlConn) writeClearAuthPacket() error {
392
394
// Native password authentication method
393
395
// http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchResponse
394
396
func (mc * mysqlConn ) writeNativeAuthPacket (cipher []byte ) error {
395
- scrambleBuff := scramblePassword (cipher , []byte (mc .cfg .Passwd ))
397
+ // https://dev.mysql.com/doc/internals/en/secure-password-authentication.html
398
+ // Native password authentication only need and will need 20-byte challenge.
399
+ scrambleBuff := scramblePassword (cipher [0 :20 ], []byte (mc .cfg .Passwd ))
396
400
397
401
// Calculate the packet length and add a tailing 0
398
402
pktLen := len (scrambleBuff )
@@ -495,7 +499,7 @@ func (mc *mysqlConn) readResultOK() ([]byte, error) {
495
499
if len (data ) > 1 {
496
500
pluginEndIndex := bytes .IndexByte (data , 0x00 )
497
501
plugin := string (data [1 :pluginEndIndex ])
498
- cipher := data [pluginEndIndex + 1 : len ( data ) - 1 ]
502
+ cipher := data [pluginEndIndex + 1 : ]
499
503
500
504
switch plugin {
501
505
case "mysql_old_password" :
0 commit comments