Random Password Generator

  • Share this:

Code introduction


This function generates a random password of a specified length, composed of uppercase and lowercase letters, digits, and special characters.


Technology Stack : datetime, re, math, random, string, os

Code Type : Generate random password

Code Difficulty : Intermediate


                
                    
import datetime
import re
import math
import random
import string
import os

def generate_random_password(length=12):
    if not isinstance(length, int) or length < 6:
        raise ValueError("Password length must be an integer greater than or equal to 6")
    
    characters = string.ascii_letters + string.digits + "!@#$%^&*()_+-="
    return ''.join(random.choice(characters) for _ in range(length))