You can download this code by clicking the button below.
This code is now available for download.
This function generates a random password of a specified length, consisting of uppercase and lowercase letters, digits, and special characters.
Technology Stack : csv, random, string, os, shutil, hashlib, re
Code Type : Generate random password
Code Difficulty : Beginner
import csv
import random
import string
import os
import shutil
import hashlib
import re
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.")
letters = string.ascii_letters + string.digits + string.punctuation
return ''.join(random.choice(letters) for i in range(length))