Random Password Generator

  • Share this:

Code introduction


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


Technology Stack : os, re, json, time, base64, hashlib, calendar, random, string

Code Type : Generate random password

Code Difficulty : Intermediate


                
                    
import os
import re
import json
import time
import base64
import hashlib
import calendar
import random
import string

def generate_random_password(length=12):
    if not isinstance(length, int) or length < 1:
        raise ValueError("Length must be a positive integer")
    characters = string.ascii_letters + string.digits
    return ''.join(random.choice(characters) for i in range(length))