You are on page 1of 1

import mysql.

connector
import random # for choosing random elements for the password
import array # This module defines an object type which can compactly
represent an arrayof
cnx = mysql.connector.connect(user='root',
password='ayaan6398',
host='3306',
database='users')
a=input('user id for which you want the password:')
pass_len = int(input('length of password:')) # length of password you want

digits = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'] # all digits

lower_case = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j','k', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z'] # all lowercase letters

upper_case = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J','K', 'M',
'N', 'O', 'p', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z'] # all uppercase letters

symbols = ['*','(', ')', '<' ':', '?', '.', '/', '|', '~', '>', '@', '#',
'$', '%', '=', ] # all symbols

mixed_list = upper_case + lower_case + digits + symbols # combine all the


lists in one

random_dig = random.choice(digits)
random_low = random.choice(lower_case)
randome_upp = random.choice(upper_case)
randome_sym = random.choice(symbols)
# use random to chose random elements from the the lists

temp_pass = random_dig + random_low + randome_upp + randome_sym #to


combine all the random lists

for i in range(pass_len - 4):# because before this


# there is only 4 elements but after this you
can have as many as you want
temp_pass = temp_pass + random.choice(mixed_list)
temp_pass2 = array.array('u', temp_pass) # to covert temp password
into array for shuffling
random.shuffle(temp_pass2) # helps from having same outcome over again

main_pass = ''
for z in temp_pass: # to creat the final password
main_pass = main_pass + z

b=main_pass
a='your password for the ID:',a,'is',':',b
print(a)
c=input("Do you want to search your password again(Y/N):")
if c=='y':
print(b)
if c=='Y':
print(b)
else:
print("Have a Good day")

You might also like