MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / is_strong_password

Function is_strong_password

other/password.py:54–80  ·  view source on GitHub ↗

This will check whether a given password is strong or not. The password must be at least as long as the provided minimum length, and it must contain at least 1 lowercase letter, 1 uppercase letter, 1 number and 1 special character. >>> is_strong_password('Hwea7$2!') True >>

(password: str, min_length: int = 8)

Source from the content-addressed store, hash-verified

52
53
54def is_strong_password(password: str, min_length: int = 8) -> bool:
55 """
56 This will check whether a given password is strong or not. The password must be at
57 least as long as the provided minimum length, and it must contain at least 1
58 lowercase letter, 1 uppercase letter, 1 number and 1 special character.
59
60 >>> is_strong_password('Hwea7$2!')
61 True
62 >>> is_strong_password('Sh0r1')
63 False
64 >>> is_strong_password('Hello123')
65 False
66 >>> is_strong_password('Hello1238udfhiaf038fajdvjjf!jaiuFhkqi1')
67 True
68 >>> is_strong_password('0')
69 False
70 """
71
72 if len(password) < min_length:
73 return False
74
75 upper = any(char in ascii_uppercase for char in password)
76 lower = any(char in ascii_lowercase for char in password)
77 num = any(char in digits for char in password)
78 spec_char = any(char in punctuation for char in password)
79
80 return upper and lower and num and spec_char
81
82
83def main():

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected