You can download this code by clicking the button below.
This code is now available for download.
This function is used to generate a random password of a specified length, composed of letters, digits, and special characters.
Technology Stack : datetime, os, random, string, sys, time
Code Type : Generate random password
Code Difficulty : Intermediate
import datetime
import os
import random
import re
import string
import sys
import time
def generate_random_password(length=12):
if length < 6:
raise ValueError("Password length must be at least 6 characters.")
characters = string.ascii_letters + string.digits + "!@#$%^&*?"
password = ''.join(random.choice(characters) for i in range(length))
return password