Write a Python program that creates passwords. Ask the user to input their name.
ID: 3833978 • Letter: W
Question
Write a Python program that creates passwords. Ask the user to input their name. You will create two passwords for the user: one simply and one complex. The simple password will consist of the first three letters of the last name followed by the first three letters of the first name and then a random number from zero through nine. The complex password will consist of five random puncuation symbols.
You must create two dictionaries to store the passwords - one for the simple passwords and one for the complex passwords.
Set up a loop to create three passwords for three users and then print out both dictionaries.
Pls help, Thank you!
Explanation / Answer
Code:
#!/usr/bin/python
import re
import random
# script name: gen_passwd.py
# script to generate simple and complex passwords
# punctuation sympbol list
symbols = ['.', ',', ';', ':', '-', '[',']','(',')','{','}','"']
# getting information on how many users we want to generate password
n_users = input("How many users you want to create password: ")
simple = {}
complex = {}
for i in range(n_users):
# getting input from the user
name = raw_input("Enter full name: ")
name_list = re.compile("s+").split(name)
# validating if atleast first and middle name is given
if (len(name_list) < 3):
print "Warning - Name should have atleast first, last and middle name"
print "Usage: python gen_passwd.py <firstname> <middle> <lastname>"
print "Example: python gen_passwd.py Henry William Shakespear"
exit()
# capturing first, middle and last names
first, middle, last = name_list[0], name_list[1], name_list[2]
# logic to generate simple password
counter = 1
sim_pass = ""
for i in last:
if(counter > 3):
break
sim_pass += i
counter += 1
counter = 1
for i in first:
if(counter > 3):
break
sim_pass += i
counter += 1
sim_pass += str(random.randint(0,9))
simple[name] = sim_pass
# logic to generate complex password
num_sym = len(symbols) - 1
com_pass = ""
for i in range(5):
com_pass += symbols[random.randint(0,num_sym)]
complex[name] = com_pass
print "Simple passwords generated are:"
for uname, passwd in simple.items():
print "%s -> %s " %(uname, passwd)
print "Complex passwords generated are:"
for uname, passwd in complex.items():
print "%s -> %s " %(uname, passwd)
Execution and output:
186590cb0725:Python bonkv$ python gen_passwd.py
How many users you want to create password: 2
Enter full name: Mary Anne Clarke
Enter full name: Joe Bob Briggs
Simple passwords generated are:
Joe Bob Briggs -> BriJoe8
Mary Anne Clarke -> ClaMar7
Complex passwords generated are:
Joe Bob Briggs -> )[}))
Mary Anne Clarke -> {".)}
186590cb0725:Python bonkv$ python gen_passwd.py
How many users you want to create password: 3
Enter full name: Michelle Wingshan Kwan
Enter full name: Jerry Chih-Yuan Yang
Enter full name: James Chu-yu Soong
Simple passwords generated are:
Jerry Chih-Yuan Yang -> YanJer4
James Chu-yu Soong -> SooJam1
Michelle Wingshan Kwan -> KwaMic2
Complex passwords generated are:
Jerry Chih-Yuan Yang -> (-"(.
James Chu-yu Soong -> :((,:
Michelle Wingshan Kwan -> (,[]{
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.