password_generator.py
1 import secrets 2 import string 3 import hashlib 4 import time 5 import os 6 7 def generate_ultra_password(length=64, extra_entropy=True): 8 if length < 32: 9 raise ValueError("Password length should be at least 32 characters") 10 11 chars = ( 12 string.ascii_lowercase + 13 string.ascii_uppercase + 14 string.digits + 15 "!@#$%^&*()_+-=[]{}|;:,.<>?" 16 ) 17 18 safe_chars = "".join(c for c in chars if c not in ""`!$()<>[]{};&|*?") 19 safe_chars += "!@#%^&*()-_=+,.;:" 20 21 password = "".join(secrets.choice(safe_chars) for _ in range(length)) 22 23 if extra_entropy: 24 entropy = f"{time.time_ns()}{os.getpid()}{secrets.token_hex(32)}" 25 hash_entropy = hashlib.sha512(entropy.encode()).hexdigest() 26 safe_hash = "".join(c for c in hash_entropy if c in safe_chars) 27 password += safe_hash 28 29 password = "".join(secrets.SystemRandom().sample(password, len(password))) 30 31 return password 32 33 34 if __name__ == "__main__": 35 ultra_password = generate_ultra_password(length=64) 36 print("Generated Password:\n") 37 print(ultra_password) 38 print("\nLength:", len(ultra_password))