@@ -359,7 +359,9 @@ func (mc *mysqlConn) writeAuthPacket(cipher []byte) error {
359
359
// http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchResponse
360
360
func (mc * mysqlConn ) writeOldAuthPacket (cipher []byte ) error {
361
361
// 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 ))
363
365
364
366
// Calculate the packet length and add a tailing 0
365
367
pktLen := len (scrambleBuff ) + 1
@@ -399,7 +401,9 @@ func (mc *mysqlConn) writeClearAuthPacket() error {
399
401
// Native password authentication method
400
402
// http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchResponse
401
403
func (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 ))
403
407
404
408
// Calculate the packet length and add a tailing 0
405
409
pktLen := len (scrambleBuff )
@@ -502,7 +506,7 @@ func (mc *mysqlConn) readResultOK() ([]byte, error) {
502
506
if len (data ) > 1 {
503
507
pluginEndIndex := bytes .IndexByte (data , 0x00 )
504
508
plugin := string (data [1 :pluginEndIndex ])
505
- cipher := data [pluginEndIndex + 1 : len ( data ) - 1 ]
509
+ cipher := data [pluginEndIndex + 1 : ]
506
510
507
511
switch plugin {
508
512
case "mysql_old_password" :
0 commit comments