Random Password Generator

  • Share this:

Code introduction


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


Technology Stack : csv, os, random, string, time, urllib.request

Code Type : Generate random password

Code Difficulty : Intermediate


                
                    
import csv
import os
import random
import re
import string
import time
import urllib.request

def generate_random_password(length=12):
    if length < 4:
        raise ValueError("Password length must be at least 4 characters.")
    characters = string.ascii_letters + string.digits + "!@#$%^&*"
    password = ''.join(random.choice(characters) for i in range(length))
    return password