You can download this code by clicking the button below.
This code is now available for download.
Generate a random password of specified length, including uppercase and lowercase letters, digits, and special characters.
Technology Stack : random, string
Code Type : Function
Code Difficulty : Intermediate
import random
import string
import re
import math
import os
import time
import json
def generate_random_password(length=12):
if not isinstance(length, int) or length < 8:
raise ValueError("Password length must be an integer greater than or equal to 8")
characters = string.ascii_letters + string.digits + string.punctuation
random_password = ''.join(random.choice(characters) for i in range(length))
return random_password