What I was trying to do here was create a Python script that would generate passwords with 16 characters with uppercase and lowercase letters, and numbers. The generated password would then write itself to a file.
Let me know what you think because I know they say the point of Python is to be able to write powerful scripts that can do what other languages can do in a few lines. I feel like this is probably way more then it should be for what it's doing.
import random
import string
print "Welcome to PassBook!"
def genPasswd():
global route
global password
global username
global account
global entry
account = raw_input("Account: ")
username = raw_input("Username: ")
key1 = random.randrange(10,100)
key2 = random.randrange(10,100)
key3 = random.randrange(10,100)
key4 = random.randrange(10,100)
keya = str(random.choice(string.letters) + random.choice(string.letters))
keyb = str(random.choice(string.letters) + random.choice(string.letters))
keyc = str(random.choice(string.letters) + random.choice(string.letters))
keyd = str(random.choice(string.letters) + random.choice(string.letters))
key1a = str(key1) + str(keya)
key2b = str(key2) + str(keyb)
key3c = str(key3) + str(keyc)
key4d = str(key4) + str(keyd)
password = str(key1a + key2b + key3c + key4d)
entry = "Account: " + account + " - Username: " + username + " - Password: " + password
file = open("/home/meta/Desktop/Python2/passbook/passbook.txt", "a")
file.write("\n" + entry + "\n")
print entry
return key1
return key2
return key3
return key4
return keya
return keyb
return keyc
return keyd
return key1a
return key2b
return key3c
return key4d
return password
return username
return account
return entry
def queryPb():
search = raw_input("For which account are you searching: ")
read = open("/home/meta/Desktop/Python2/passbook/passbook.txt", "r")
for line in read:
if search in line:
print line
return line
else:
print "I'm sorry we could not find any account related to " + search
def takeRoute():
global route
route = raw_input("Press 1 to generate a password, Press 2 to search for an existing account: ")
if int(route) ==1:
genPasswd()
elif int(route) == 2:
queryPb()
else:
print "I'm sorry that is not an option!"
exit()
takeRoute()