|
| 1 | +# This Will Check Whether A Given Password Is Strong Or Not |
| 2 | +# It Follows The Rule that Length Of Password Should Be At Least 8 Characters |
| 3 | +# And At Least 1 Lower, 1 Upper, 1 Number And 1 Special Character |
| 4 | + |
| 5 | +from string import ascii_lowercase, ascii_uppercase, digits, punctuation |
| 6 | + |
| 7 | + |
| 8 | +def strong_password_detector(password: str, min_length: int = 8) -> str: |
| 9 | + """ |
| 10 | + >>> strong_password_detector('Hwea7$2!') |
| 11 | + 'This is a strong Password' |
| 12 | +
|
| 13 | + >>> strong_password_detector('Sh0r1') |
| 14 | + 'Your Password must be at least 8 characters long' |
| 15 | +
|
| 16 | + >>> strong_password_detector('Hello123') |
| 17 | + 'Password should contain UPPERCASE, lowercase, numbers, special characters' |
| 18 | +
|
| 19 | + >>> strong_password_detector('Hello1238udfhiaf038fajdvjjf!jaiuFhkqi1') |
| 20 | + 'This is a strong Password' |
| 21 | +
|
| 22 | + >>> strong_password_detector(0) |
| 23 | + 'Your Password must be at least 8 characters long' |
| 24 | + """ |
| 25 | + |
| 26 | + if len(str(password)) < 8: |
| 27 | + return "Your Password must be at least 8 characters long" |
| 28 | + |
| 29 | + upper = any(char in ascii_uppercase for char in password) |
| 30 | + lower = any(char in ascii_lowercase for char in password) |
| 31 | + num = any(char in digits for char in password) |
| 32 | + spec_char = any(char in punctuation for char in password) |
| 33 | + |
| 34 | + if upper and lower and num and spec_char: |
| 35 | + return "This is a strong Password" |
| 36 | + |
| 37 | + else: |
| 38 | + return ( |
| 39 | + "Password should contain UPPERCASE, lowercase, " |
| 40 | + "numbers, special characters" |
| 41 | + ) |
| 42 | + |
| 43 | + |
| 44 | +if __name__ == "__main__": |
| 45 | + import doctest |
| 46 | + |
| 47 | + doctest.testmod() |
0 commit comments