feat: added password quality check
This commit is contained in:
+15
-1
@@ -29,8 +29,22 @@ def generate_insane_password(length: int) -> str:
|
||||
ascii_pool: str = ''.join(chr(i) for i in chain(range(40, 127), range(180, 256)))
|
||||
return ''.join(secrets.choice(ascii_pool) for _ in range(length))
|
||||
|
||||
def password_qc(pw: str) -> bool:
|
||||
specials = set("!@#$%^&*()-_=+[]{};:'\"|,.<>/?`~\\")
|
||||
|
||||
has_lower = any(c.islower() for c in pw)
|
||||
has_upper = any(c.isupper() for c in pw)
|
||||
has_digit = any(c.isdigit() for c in pw)
|
||||
has_special = any(c in specials for c in pw)
|
||||
|
||||
return has_lower and has_upper and has_digit and has_special
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) <= 1:
|
||||
print(generate_password(3))
|
||||
elif sys.argv[1] == '-insane' or sys.argv[1] == '-i':
|
||||
print(generate_insane_password(20))
|
||||
pw = generate_insane_password(20)
|
||||
while not password_qc(pw):
|
||||
pw = generate_insane_password(20)
|
||||
else:
|
||||
print(pw)
|
||||
|
||||
Reference in New Issue
Block a user