mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-20 00:02:04 +00:00
refactor: Condense password
related files in one (#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 <cclauss@me.com> * 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 <cclauss@me.com>
This commit is contained in:
parent
f05baa2b2b
commit
598f6a26a1
|
@ -112,12 +112,12 @@ def mincost_tickets(days: list[int], costs: list[int]) -> int:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if index not in days_set:
|
if index not in days_set:
|
||||||
return dp(index + 1)
|
return dynamic_programming(index + 1)
|
||||||
|
|
||||||
return min(
|
return min(
|
||||||
costs[0] + dp(index + 1),
|
costs[0] + dynamic_programming(index + 1),
|
||||||
costs[1] + dp(index + 7),
|
costs[1] + dynamic_programming(index + 7),
|
||||||
costs[2] + dp(index + 30),
|
costs[2] + dynamic_programming(index + 30),
|
||||||
)
|
)
|
||||||
|
|
||||||
return dynamic_programming(1)
|
return dynamic_programming(1)
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
# This Will Check Whether A Given Password Is Strong Or Not
|
|
||||||
# It Follows The Rule that Length Of Password Should Be At Least 8 Characters
|
|
||||||
# And At Least 1 Lower, 1 Upper, 1 Number And 1 Special Character
|
|
||||||
|
|
||||||
from string import ascii_lowercase, ascii_uppercase, digits, punctuation
|
|
||||||
|
|
||||||
|
|
||||||
def strong_password_detector(password: str, min_length: int = 8) -> str:
|
|
||||||
"""
|
|
||||||
>>> strong_password_detector('Hwea7$2!')
|
|
||||||
'This is a strong Password'
|
|
||||||
|
|
||||||
>>> strong_password_detector('Sh0r1')
|
|
||||||
'Your Password must be at least 8 characters long'
|
|
||||||
|
|
||||||
>>> strong_password_detector('Hello123')
|
|
||||||
'Password should contain UPPERCASE, lowercase, numbers, special characters'
|
|
||||||
|
|
||||||
>>> strong_password_detector('Hello1238udfhiaf038fajdvjjf!jaiuFhkqi1')
|
|
||||||
'This is a strong Password'
|
|
||||||
|
|
||||||
>>> strong_password_detector(0)
|
|
||||||
'Your Password must be at least 8 characters long'
|
|
||||||
"""
|
|
||||||
|
|
||||||
if len(str(password)) < 8:
|
|
||||||
return "Your Password must be at least 8 characters long"
|
|
||||||
|
|
||||||
upper = any(char in ascii_uppercase for char in password)
|
|
||||||
lower = any(char in ascii_lowercase for char in password)
|
|
||||||
num = any(char in digits for char in password)
|
|
||||||
spec_char = any(char in punctuation for char in password)
|
|
||||||
|
|
||||||
if upper and lower and num and spec_char:
|
|
||||||
return "This is a strong Password"
|
|
||||||
|
|
||||||
else:
|
|
||||||
return (
|
|
||||||
"Password should contain UPPERCASE, lowercase, "
|
|
||||||
"numbers, special characters"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
import doctest
|
|
||||||
|
|
||||||
doctest.testmod()
|
|
|
@ -1,11 +1,12 @@
|
||||||
"""Password Generator allows you to generate a random password of length N."""
|
|
||||||
import secrets
|
import secrets
|
||||||
from random import shuffle
|
from random import shuffle
|
||||||
from string import ascii_letters, digits, punctuation
|
from string import ascii_letters, ascii_lowercase, ascii_uppercase, digits, punctuation
|
||||||
|
|
||||||
|
|
||||||
def password_generator(length: int = 8) -> str:
|
def password_generator(length: int = 8) -> str:
|
||||||
"""
|
"""
|
||||||
|
Password Generator allows you to generate a random password of length N.
|
||||||
|
|
||||||
>>> len(password_generator())
|
>>> len(password_generator())
|
||||||
8
|
8
|
||||||
>>> len(password_generator(length=16))
|
>>> len(password_generator(length=16))
|
||||||
|
@ -62,6 +63,45 @@ def random_characters(chars_incl, i):
|
||||||
pass # Put your code here...
|
pass # Put your code here...
|
||||||
|
|
||||||
|
|
||||||
|
# This Will Check Whether A Given Password Is Strong Or Not
|
||||||
|
# It Follows The Rule that Length Of Password Should Be At Least 8 Characters
|
||||||
|
# And At Least 1 Lower, 1 Upper, 1 Number And 1 Special Character
|
||||||
|
def strong_password_detector(password: str, min_length: int = 8) -> str:
|
||||||
|
"""
|
||||||
|
>>> strong_password_detector('Hwea7$2!')
|
||||||
|
'This is a strong Password'
|
||||||
|
|
||||||
|
>>> strong_password_detector('Sh0r1')
|
||||||
|
'Your Password must be at least 8 characters long'
|
||||||
|
|
||||||
|
>>> strong_password_detector('Hello123')
|
||||||
|
'Password should contain UPPERCASE, lowercase, numbers, special characters'
|
||||||
|
|
||||||
|
>>> strong_password_detector('Hello1238udfhiaf038fajdvjjf!jaiuFhkqi1')
|
||||||
|
'This is a strong Password'
|
||||||
|
|
||||||
|
>>> strong_password_detector('0')
|
||||||
|
'Your Password must be at least 8 characters long'
|
||||||
|
"""
|
||||||
|
|
||||||
|
if len(password) < min_length:
|
||||||
|
return "Your Password must be at least 8 characters long"
|
||||||
|
|
||||||
|
upper = any(char in ascii_uppercase for char in password)
|
||||||
|
lower = any(char in ascii_lowercase for char in password)
|
||||||
|
num = any(char in digits for char in password)
|
||||||
|
spec_char = any(char in punctuation for char in password)
|
||||||
|
|
||||||
|
if upper and lower and num and spec_char:
|
||||||
|
return "This is a strong Password"
|
||||||
|
|
||||||
|
else:
|
||||||
|
return (
|
||||||
|
"Password should contain UPPERCASE, lowercase, "
|
||||||
|
"numbers, special characters"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
length = int(input("Please indicate the max length of your password: ").strip())
|
length = int(input("Please indicate the max length of your password: ").strip())
|
||||||
chars_incl = input(
|
chars_incl = input(
|
|
@ -1,5 +1,4 @@
|
||||||
beautifulsoup4
|
beautifulsoup4
|
||||||
cython>=0.29.28 # For statsmodels on Python 3.11
|
|
||||||
fake_useragent
|
fake_useragent
|
||||||
keras
|
keras
|
||||||
lxml
|
lxml
|
||||||
|
|
Loading…
Reference in New Issue
Block a user