Skip to content

Commit

Permalink
PEP Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
CheeseCake87 committed Sep 22, 2023
1 parent 6f6608a commit 7ded28d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 96 deletions.
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ testing =
tox>=3.24

[flake8]
max-line-length = 160
max-line-length = 160
ignore = W293
94 changes: 3 additions & 91 deletions src/flask_imp/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def is_username_valid(cls, username: str, allowed: str = "all") -> bool:
.. note::
This method is unstable and needs to be reworked.
:raw-html:`<br />`
-----
Expand Down Expand Up @@ -120,11 +119,10 @@ def generate_salt(cls) -> str:
def generate_private_key(cls, hook: str) -> str:
"""
Generates a sha256 private key from a passed in hook value.
:raw-html:`<br />`
For use in any private key generation.
:raw-html:`<br />`
-----
Expand Down Expand Up @@ -158,7 +156,7 @@ def generate_numeric_validator(cls, length: int) -> int:
@classmethod
def generate_email_validator(cls) -> str:
"""
Uses generate_numeric_validator with a length of 8 to
Uses generate_numeric_validator with a length of 8 to
generate a random number for the specific use of
validating accounts via email.
Expand Down Expand Up @@ -439,89 +437,3 @@ class PasswordGeneration:
'Pumpkin', 'Indian', 'Crimson', 'Tiffany', 'Gunmetal', 'Salad', 'Platinum', 'MediumAquaMarine',
'Bronze', 'Lava', 'Peach', 'Tyrian', 'Rust', 'Petra', 'Lovely', 'Aloe', 'Blossom', 'Rat', 'Shocking',
'LawnGreen', 'YellowGreen', 'Turquoise']


if __name__ == '__main__':
import timeit
import statistics
import functools

# on page testing:

pepper_lengths = [1, 2, 3]
runs = 100
results: list[str] = []

print("Testing password hashing and guessing speed, please wait...")


def auth_password(pl: int, cor_pass: bool):
incorrect_pass = Auth.generate_password()
correct_pass = Auth.generate_password()
db_salt = Auth.generate_salt()
db_pass = Auth.hash_password(correct_pass, db_salt, pepper_length=pl)

if cor_pass:
Auth.auth_password(correct_pass, db_pass, db_salt, pepper_length=pl)
else:
Auth.auth_password(incorrect_pass, db_pass, db_salt, pepper_length=pl)


for _pepper_length in pepper_lengths:
times = []
for i in range(runs):
times.append(
timeit.timeit(
functools.partial(auth_password, _pepper_length, True),
number=1
)
)
results.append(
f"# Avr time: {statistics.mean(times):.4f} seconds, for "
f"pepper length of {_pepper_length} ({runs} runs, correct password given)"
)

for _pepper_length in pepper_lengths:
times = []
for i in range(runs):
times.append(
timeit.timeit(
functools.partial(auth_password, _pepper_length, False),
number=1
)
)
results.append(
f"# Avr time: {statistics.mean(times):.4f} seconds, for "
f"pepper length of {_pepper_length} ({runs} runs, incorrect password given)"
)

for result in results:
print(result)

# Avr time: 0.0001 seconds, for pepper length of 1 (100 runs, correct password given)
# Avr time: 0.0020 seconds, for pepper length of 2 (100 runs, correct password given)
# Avr time: 0.1132 seconds, for pepper length of 3 (100 runs, correct password given)
# Avr time: 0.0001 seconds, for pepper length of 1 (100 runs, incorrect password given)
# Avr time: 0.0040 seconds, for pepper length of 2 (100 runs, incorrect password given)
# Avr time: 0.1944 seconds, for pepper length of 3 (100 runs, incorrect password given)

# Avr time: 0.0001 seconds, for pepper length of 1 (100 runs, correct password given)
# Avr time: 0.0020 seconds, for pepper length of 2 (100 runs, correct password given)
# Avr time: 0.1026 seconds, for pepper length of 3 (100 runs, correct password given)
# Avr time: 0.0001 seconds, for pepper length of 1 (100 runs, incorrect password given)
# Avr time: 0.0037 seconds, for pepper length of 2 (100 runs, incorrect password given)
# Avr time: 0.2049 seconds, for pepper length of 3 (100 runs, incorrect password given)

# Avr time: 0.0001 seconds, for pepper length of 1 (100 runs, correct password given)
# Avr time: 0.0024 seconds, for pepper length of 2 (100 runs, correct password given)
# Avr time: 0.1066 seconds, for pepper length of 3 (100 runs, correct password given)
# Avr time: 0.0001 seconds, for pepper length of 1 (100 runs, incorrect password given)
# Avr time: 0.0035 seconds, for pepper length of 2 (100 runs, incorrect password given)
# Avr time: 0.1947 seconds, for pepper length of 3 (100 runs, incorrect password given)

# Avr time: 0.0001 seconds, for pepper length of 1 (100 runs, correct password given)
# Avr time: 0.0020 seconds, for pepper length of 2 (100 runs, correct password given)
# Avr time: 0.1036 seconds, for pepper length of 3 (100 runs, correct password given)
# Avr time: 0.0001 seconds, for pepper length of 1 (100 runs, incorrect password given)
# Avr time: 0.0037 seconds, for pepper length of 2 (100 runs, incorrect password given)
# Avr time: 0.1989 seconds, for pepper length of 3 (100 runs, incorrect password given)
6 changes: 4 additions & 2 deletions src/flask_imp/imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,13 @@ def dev():
:raw-html:`<br />`
scope_root_folders_to=["cli", "routes"] => will only import files from `<folder>/cli/\*.py` and `<folder>/routes/*.py`
scope_root_folders_to=["cli", "routes"] => will only import files from `<folder>/cli/*.py`
and `<folder>/routes/*.py`
:raw-html:`<br />`
scope_root_files_to=["cli.py", "routes.py"] => will only import the files `<folder>/cli.py` and `<folder>/routes.py`
scope_root_files_to=["cli.py", "routes.py"] => will only import the files `<folder>/cli.py`
and `<folder>/routes.py`
:raw-html:`<br />`
Expand Down
2 changes: 0 additions & 2 deletions src/flask_imp/registeries.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
class ModelRegistry:
"""
A registry for SQLAlchemy models.
This is used to store all imported SQLAlchemy models in a central location.
Accessible via Imp.__model_registry__
"""
registry: t.Dict[str, t.Any]
Expand Down

0 comments on commit 7ded28d

Please sign in to comment.