Skip to content

Commit 84f6018

Browse files
committed
fix long password authentication failure
1 parent 5cd720a commit 84f6018

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

packets.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -459,12 +459,11 @@ func (mc *mysqlConn) writePublicKeyAuthPacket(cipher []byte) error {
459459
return err
460460
}
461461

462-
plain := make([]byte, 20)
463-
for k, v := range []byte(mc.cfg.Passwd) {
464-
plain[k] = byte(v)
465-
}
462+
plain := make([]byte, len(mc.cfg.Passwd) + 1)
463+
copy(plain, mc.cfg.Passwd)
466464
for i := range plain {
467-
plain[i] ^= cipher[i]
465+
j := i % len(cipher)
466+
plain[i] ^= cipher[j]
468467
}
469468
sha1 := sha1.New()
470469
enc, _ := rsa.EncryptOAEP(sha1, rand.Reader, pub.(*rsa.PublicKey), plain, nil)

0 commit comments

Comments
 (0)