Random Password Generator

  • Share this:

Code introduction


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


Technology Stack : random, string, re

Code Type : Generate random password

Code Difficulty : Intermediate


                
                    
import random
import string
import re
import sys
import time
import datetime
import os
import shutil
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

def generate_random_password(length):
    if not isinstance(length, int) or length < 8:
        raise ValueError("Password length must be an integer greater than or equal to 8")
    return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(length))                
              
Tags: