Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
65 views2 pages

Password Generator

The document contains a Python program to generate random passwords of variable lengths by concatenating random letters, numbers, and uppercase letters. The program takes user input for the number of passwords and each password length, generates the passwords using defined functions, and prints the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views2 pages

Password Generator

The document contains a Python program to generate random passwords of variable lengths by concatenating random letters, numbers, and uppercase letters. The program takes user input for the number of passwords and each password length, generates the passwords using defined functions, and prints the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import random

def generatePassword(pwlength):

alphabet = "abcdefghijklmnopqrstuvwxyz"

passwords = []

for i in pwlength:

password = ""
for j in range(i):
next_letter_index = random.randrange(len(alphabet))
password = password + alphabet[next_letter_index]
password = replaceWithNumber(password)
password = replaceWithUppercaseLetter(password)

passwords.append(password)

return passwords

def replaceWithNumber(pword):
for i in range(random.randrange(1,3)):
replace_index = random.randrange(len(pword)//2)
pword = pword[0:replace_index] + str(random.randrange(10)) +
pword[replace_index+1:]
return pword

def replaceWithUppercaseLetter(pword):
for i in range(random.randrange(1,3)):
replace_index = random.randrange(len(pword)//2,len(pword))
pword = pword[0:replace_index] + pword[replace_index].upper() +
pword[replace_index+1:]
return pword

def main():

numPasswords = int(input("How many passwords do you want to generate? "))

print("Generating " +str(numPasswords)+" passwords")

passwordLengths = []

print("Minimum length of password should be 3....!!\n"


"If you will put less than 3 in it,it will still give you 3 digit
password... ")

for i in range(numPasswords):
length = int(input("Enter the length of Password #" + str(i+1) + " "))
if length<3:
length = 3
passwordLengths.append(length)

Password = generatePassword(passwordLengths)

for i in range(numPasswords):
print ("Password #"+str(i+1)+" = " + Password[i])

main()

You might also like