fork download
  1. import hashlib
  2. import os
  3.  
  4. def generate_hashed_password(password: str):
  5. # Generate a random salt
  6. salt = os.urandom(31).hex() # Convert to a readable hexadecimal string
  7. # Combine the password and the salt
  8. salted_password = password + salt
  9. # Hash the combined password and salt using MD5
  10. hashed_password = hashlib.md5(salted_password.encode()).hexdigest()
  11. return salt, hashed_password
  12.  
  13. # Example usage
  14. password = "user1234"
  15. salt, hashed_password = generate_hashed_password(password)
  16.  
  17. print(f"Salt: {salt}")
  18. print(f"Hashed Password: {hashed_password}")
  19.  
Success #stdin #stdout 0.03s 11524KB
stdin
Standard input is empty
stdout
Salt: 1449d2bef7718fa6b8268fab398fe5c32e5dcb0cfcc81f8329556188233b26
Hashed Password: 25e5d8737a15b1494f7bec3210e0ae0d