|
1 |
| -"""Password Generator allows you to generate a random password of length N.""" |
2 | 1 | import secrets
|
3 | 2 | from random import shuffle
|
4 |
| -from string import ascii_letters, digits, punctuation |
| 3 | +from string import ascii_letters, ascii_lowercase, ascii_uppercase, digits, punctuation |
5 | 4 |
|
6 | 5 |
|
7 | 6 | def password_generator(length: int = 8) -> str:
|
8 | 7 | """
|
| 8 | + Password Generator allows you to generate a random password of length N. |
| 9 | +
|
9 | 10 | >>> len(password_generator())
|
10 | 11 | 8
|
11 | 12 | >>> len(password_generator(length=16))
|
@@ -62,6 +63,45 @@ def random_characters(chars_incl, i):
|
62 | 63 | pass # Put your code here...
|
63 | 64 |
|
64 | 65 |
|
| 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 | + |
65 | 105 | def main():
|
66 | 106 | length = int(input("Please indicate the max length of your password: ").strip())
|
67 | 107 | chars_incl = input(
|
|
0 commit comments