Skip to content

Commit 598f6a2

Browse files
CaedenPHpre-commit-ci[bot]cclauss
authored
refactor: Condense password related files in one (TheAlgorithms#7939)
* refactor: Condense `password` related files in one * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update other/password.py Co-authored-by: Christian Clauss <[email protected]> * dynamic_programming * test: Make test input `str` * requirements.txt: Remove cython>=0.29.28 # For statsmodels on Python 3.11 Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <[email protected]>
1 parent f05baa2 commit 598f6a2

File tree

4 files changed

+46
-54
lines changed

4 files changed

+46
-54
lines changed

dynamic_programming/minimum_tickets_cost.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ def dynamic_programming(index: int) -> int:
112112
return 0
113113

114114
if index not in days_set:
115-
return dp(index + 1)
115+
return dynamic_programming(index + 1)
116116

117117
return min(
118-
costs[0] + dp(index + 1),
119-
costs[1] + dp(index + 7),
120-
costs[2] + dp(index + 30),
118+
costs[0] + dynamic_programming(index + 1),
119+
costs[1] + dynamic_programming(index + 7),
120+
costs[2] + dynamic_programming(index + 30),
121121
)
122122

123123
return dynamic_programming(1)

other/check_strong_password.py

-47
This file was deleted.

other/password_generator.py other/password.py

+42-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
"""Password Generator allows you to generate a random password of length N."""
21
import secrets
32
from random import shuffle
4-
from string import ascii_letters, digits, punctuation
3+
from string import ascii_letters, ascii_lowercase, ascii_uppercase, digits, punctuation
54

65

76
def password_generator(length: int = 8) -> str:
87
"""
8+
Password Generator allows you to generate a random password of length N.
9+
910
>>> len(password_generator())
1011
8
1112
>>> len(password_generator(length=16))
@@ -62,6 +63,45 @@ def random_characters(chars_incl, i):
6263
pass # Put your code here...
6364

6465

66+
# This Will Check Whether A Given Password Is Strong Or Not
67+
# It Follows The Rule that Length Of Password Should Be At Least 8 Characters
68+
# And At Least 1 Lower, 1 Upper, 1 Number And 1 Special Character
69+
def strong_password_detector(password: str, min_length: int = 8) -> str:
70+
"""
71+
>>> strong_password_detector('Hwea7$2!')
72+
'This is a strong Password'
73+
74+
>>> strong_password_detector('Sh0r1')
75+
'Your Password must be at least 8 characters long'
76+
77+
>>> strong_password_detector('Hello123')
78+
'Password should contain UPPERCASE, lowercase, numbers, special characters'
79+
80+
>>> strong_password_detector('Hello1238udfhiaf038fajdvjjf!jaiuFhkqi1')
81+
'This is a strong Password'
82+
83+
>>> strong_password_detector('0')
84+
'Your Password must be at least 8 characters long'
85+
"""
86+
87+
if len(password) < min_length:
88+
return "Your Password must be at least 8 characters long"
89+
90+
upper = any(char in ascii_uppercase for char in password)
91+
lower = any(char in ascii_lowercase for char in password)
92+
num = any(char in digits for char in password)
93+
spec_char = any(char in punctuation for char in password)
94+
95+
if upper and lower and num and spec_char:
96+
return "This is a strong Password"
97+
98+
else:
99+
return (
100+
"Password should contain UPPERCASE, lowercase, "
101+
"numbers, special characters"
102+
)
103+
104+
65105
def main():
66106
length = int(input("Please indicate the max length of your password: ").strip())
67107
chars_incl = input(

requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
beautifulsoup4
2-
cython>=0.29.28 # For statsmodels on Python 3.11
32
fake_useragent
43
keras
54
lxml

0 commit comments

Comments
 (0)