This is an automatic password generator which gives passwords to the user depending on the number of characters they want in their password.
Steps to execute:
1. On running the program, they user is asked the number of passwords they want to generate.
2.On entering the number of passwords, the application then asks the numeber of characters they want in each of the paswords.
3. On entering the the details the passwords are displayed to the user.
This application could be used to improve security.
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") 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()
OUTPUT:
How many passwords do you want to generate? 3
Generating 3 passwords
Minimum length of password should be 3
Enter the length of Password #1 7
Enter the length of Password #2 3
Enter the length of Password #3 10
Password #1 = 1niLlin
Password #2 = 3sT
Password #3 = glpa2zuPjm
OUTPUT
Submitted by Sandra Marin Rajesh (smr)
Download packets of source code on Coders Packet
Comments