Skip to content

Commit cd61e56

Browse files
authored
Remove old_password support (#922)
1 parent 3481889 commit cd61e56

1 file changed

Lines changed: 0 additions & 63 deletions

File tree

pymysql/_auth.py

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Implements auth methods
33
"""
44
from .err import OperationalError
5-
from .util import byte2int, int2byte
65

76

87
try:
@@ -16,9 +15,6 @@
1615

1716
from functools import partial
1817
import hashlib
19-
import io
20-
import struct
21-
import warnings
2218

2319

2420
DEBUG = False
@@ -53,65 +49,6 @@ def _my_crypt(message1, message2):
5349
return bytes(result)
5450

5551

56-
# old_passwords support ported from libmysql/password.c
57-
# https://dev.mysql.com/doc/internals/en/old-password-authentication.html
58-
59-
SCRAMBLE_LENGTH_323 = 8
60-
61-
62-
class RandStruct_323:
63-
def __init__(self, seed1, seed2):
64-
self.max_value = 0x3FFFFFFF
65-
self.seed1 = seed1 % self.max_value
66-
self.seed2 = seed2 % self.max_value
67-
68-
def my_rnd(self):
69-
self.seed1 = (self.seed1 * 3 + self.seed2) % self.max_value
70-
self.seed2 = (self.seed1 + self.seed2 + 33) % self.max_value
71-
return float(self.seed1) / float(self.max_value)
72-
73-
74-
def scramble_old_password(password, message):
75-
"""Scramble for old_password"""
76-
warnings.warn(
77-
"old password (for MySQL <4.1) is used. Upgrade your password with newer auth method.\n"
78-
"old password support will be removed in future PyMySQL version"
79-
)
80-
hash_pass = _hash_password_323(password)
81-
hash_message = _hash_password_323(message[:SCRAMBLE_LENGTH_323])
82-
hash_pass_n = struct.unpack(">LL", hash_pass)
83-
hash_message_n = struct.unpack(">LL", hash_message)
84-
85-
rand_st = RandStruct_323(
86-
hash_pass_n[0] ^ hash_message_n[0], hash_pass_n[1] ^ hash_message_n[1]
87-
)
88-
outbuf = io.BytesIO()
89-
for _ in range(min(SCRAMBLE_LENGTH_323, len(message))):
90-
outbuf.write(int2byte(int(rand_st.my_rnd() * 31) + 64))
91-
extra = int2byte(int(rand_st.my_rnd() * 31))
92-
out = outbuf.getvalue()
93-
outbuf = io.BytesIO()
94-
for c in out:
95-
outbuf.write(int2byte(byte2int(c) ^ byte2int(extra)))
96-
return outbuf.getvalue()
97-
98-
99-
def _hash_password_323(password):
100-
nr = 1345345333
101-
add = 7
102-
nr2 = 0x12345671
103-
104-
# x in py3 is numbers, p27 is chars
105-
for c in [byte2int(x) for x in password if x not in (" ", "\t", 32, 9)]:
106-
nr ^= (((nr & 63) + add) * c) + (nr << 8) & 0xFFFFFFFF
107-
nr2 = (nr2 + ((nr2 << 8) ^ nr)) & 0xFFFFFFFF
108-
add = (add + c) & 0xFFFFFFFF
109-
110-
r1 = nr & ((1 << 31) - 1) # kill sign bits
111-
r2 = nr2 & ((1 << 31) - 1)
112-
return struct.pack(">LL", r1, r2)
113-
114-
11552
# MariaDB's client_ed25519-plugin
11653
# https://mariadb.com/kb/en/library/connection/#client_ed25519-plugin
11754

0 commit comments

Comments
 (0)