@@ -359,7 +359,9 @@ func (mc *mysqlConn) writeAuthPacket(cipher []byte) error {
359359// http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchResponse
360360func (mc * mysqlConn ) writeOldAuthPacket (cipher []byte ) error {
361361 // User password
362- scrambleBuff := scrambleOldPassword (cipher , []byte (mc .cfg .Passwd ))
362+ // https://dev.mysql.com/doc/internals/en/old-password-authentication.html
363+ // Old password authentication only need and will need 8-byte challenge.
364+ scrambleBuff := scrambleOldPassword (cipher [:8 ], []byte (mc .cfg .Passwd ))
363365
364366 // Calculate the packet length and add a tailing 0
365367 pktLen := len (scrambleBuff ) + 1
@@ -399,7 +401,9 @@ func (mc *mysqlConn) writeClearAuthPacket() error {
399401// Native password authentication method
400402// http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchResponse
401403func (mc * mysqlConn ) writeNativeAuthPacket (cipher []byte ) error {
402- scrambleBuff := scramblePassword (cipher , []byte (mc .cfg .Passwd ))
404+ // https://dev.mysql.com/doc/internals/en/secure-password-authentication.html
405+ // Native password authentication only need and will need 20-byte challenge.
406+ scrambleBuff := scramblePassword (cipher [0 :20 ], []byte (mc .cfg .Passwd ))
403407
404408 // Calculate the packet length and add a tailing 0
405409 pktLen := len (scrambleBuff )
@@ -502,7 +506,7 @@ func (mc *mysqlConn) readResultOK() ([]byte, error) {
502506 if len (data ) > 1 {
503507 pluginEndIndex := bytes .IndexByte (data , 0x00 )
504508 plugin := string (data [1 :pluginEndIndex ])
505- cipher := data [pluginEndIndex + 1 : len ( data ) - 1 ]
509+ cipher := data [pluginEndIndex + 1 : ]
506510
507511 switch plugin {
508512 case "mysql_old_password" :
0 commit comments