mirror of
https://github.com/django/django.git
synced 2025-03-11 09:52:38 +00:00
Improved performance of loading common passwords in CommonPasswordValidator.
CommonPasswordValidator.__init__ previously called either splitlines or readlines, creating an unneeded intermediate list in memory. For large custom password files, this could be burdensome.
This commit is contained in:
parent
f011d9ea56
commit
28eac41510
@ -171,13 +171,11 @@ class CommonPasswordValidator:
|
|||||||
|
|
||||||
def __init__(self, password_list_path=DEFAULT_PASSWORD_LIST_PATH):
|
def __init__(self, password_list_path=DEFAULT_PASSWORD_LIST_PATH):
|
||||||
try:
|
try:
|
||||||
with gzip.open(str(password_list_path)) as f:
|
with gzip.open(str(password_list_path), 'rt') as f:
|
||||||
common_passwords_lines = f.read().decode().splitlines()
|
self.passwords = {x.strip() for x in f}
|
||||||
except OSError:
|
except OSError:
|
||||||
with open(str(password_list_path)) as f:
|
with open(str(password_list_path)) as f:
|
||||||
common_passwords_lines = f.readlines()
|
self.passwords = {x.strip() for x in f}
|
||||||
|
|
||||||
self.passwords = {p.strip() for p in common_passwords_lines}
|
|
||||||
|
|
||||||
def validate(self, password, user=None):
|
def validate(self, password, user=None):
|
||||||
if password.lower().strip() in self.passwords:
|
if password.lower().strip() in self.passwords:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user