@@ -352,7 +352,9 @@ func (mc *mysqlConn) writeAuthPacket(cipher []byte) error {
352352// http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchResponse
353353func (mc * mysqlConn ) writeOldAuthPacket (cipher []byte ) error {
354354 // 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 ))
356358
357359 // Calculate the packet length and add a tailing 0
358360 pktLen := len (scrambleBuff ) + 1
@@ -392,7 +394,9 @@ func (mc *mysqlConn) writeClearAuthPacket() error {
392394// Native password authentication method
393395// http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchResponse
394396func (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 ))
396400
397401 // Calculate the packet length and add a tailing 0
398402 pktLen := len (scrambleBuff )
@@ -495,7 +499,7 @@ func (mc *mysqlConn) readResultOK() ([]byte, error) {
495499 if len (data ) > 1 {
496500 pluginEndIndex := bytes .IndexByte (data , 0x00 )
497501 plugin := string (data [1 :pluginEndIndex ])
498- cipher := data [pluginEndIndex + 1 : len ( data ) - 1 ]
502+ cipher := data [pluginEndIndex + 1 : ]
499503
500504 switch plugin {
501505 case "mysql_old_password" :
0 commit comments