Recently searched:

Password Generator PythonCloud 

Cloud Password Generator Python

robertxxx

User
User ID
20338
Joined
Jul 7, 2023
Messages
39
Reaction score
6
#CR
3
robertxxx has not provided any additional information.
import random

import string



def generate_password(length, use_uppercase, use_numbers, use_special_chars):

char_sets = []

if use_uppercase:

char_sets.append(list(string.ascii_uppercase))

if use_numbers:

char_sets.append(list(string.digits))

if use_special_chars:

char_sets.append(list(string.punctuation))

char_sets.append(list(string.ascii_lowercase)) # Always include lowercase letters



# Shuffle each list to ensure randomness

for char_set in char_sets:

random.shuffle(char_set)



# Interleave the lists to create the password

password = []

for i in range(length):

char_set_index = i % len(char_sets)

password.append(char_sets[char_set_index].pop())



# Join the password list into a string

password = ''.join(password)



return password



# Get user input

while True:

use_uppercase = input("Include uppercase letters? (yes/no): ").lower() == 'yes'

use_numbers = input("Include numbers? (yes/no): ").lower() == 'yes'

use_special_chars = input("Include special characters? (yes/no): ").lower() == 'yes'



# Check if at least two character types are selected

if sum([use_uppercase, use_numbers, use_special_chars]) >= 2:

break

else:

print("Please select at least two character types.")



# Get password length

while True:

try:

length = int(input("Enter the desired password length (min 8): "))

if length < 8:

print("Password length must be at least 8 characters.")

else:

break

except ValueError:

print("Invalid input. Please enter a whole number.")



# Generate the password

password = generate_password(length, use_uppercase, use_numbers, use_special_chars)



print("Generated Password:", password)
 
Home Register
Top Bottom