Python Forum
Password Saver Project
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Password Saver Project
#3
import csv
import sys

#The password list - We start with it populated for testing purposes
passwords = [["yahoo","XqffoZeo"],["google","CoIushujSetu"]]


#The password file name to store the passwords to
passwordFileName = "samplePasswordFile"

#The encryption key for the caesar cypher
encryptionKey=16

#Caesar Cypher Encryption
def passwordEncrypt (unencryptedMessage, key):

    #We will start with an empty string as our encryptedMessage
    encryptedMessage = ''

    #For each symbol in the unencryptedMessage we will add an encrypted symbol into the encryptedMessage
    for symbol in unencryptedMessage:
        if symbol.isalpha():
            num = ord(symbol)
            num += key

            if symbol.isupper():
                if num > ord('Z'):
                    num -= 26
                elif num < ord('A'):
                    num += 26
            elif symbol.islower():
                if num > ord('z'):
                    num -= 26
                elif num < ord('a'):
                    num += 26

            encryptedMessage += chr(num)
        else:
            encryptedMessage += symbol

    return encryptedMessage

def loadPasswordFile(fileName):

    with open(fileName, newline='') as csvfile:
        passwordreader = csv.reader(csvfile)
        passwordList = list(passwordreader)

    return passwordList

def savePasswordFile(passwordList, fileName):

    with open(fileName, 'w+', newline='') as csvfile:
        passwordwriter = csv.writer(csvfile)
        passwordwriter.writerows(passwordList)



while True:
    print("What would you like to do:")
    print(" 1. Open password file")
    print(" 2. Lookup a password")
    print(" 3. Add a password")
    print(" 4. Save password file")
    print(" 5. Print the encrypted password list (for testing)")
    print(" 6. Quit program")
    print(" 7. Delete a password")
    print("Please enter a number (1-7)")
    choice = input()

    if(choice == '1'): #Load the password list from a file
        passwords = loadPasswordFile(passwordFileName)

    if(choice == '2'): #Lookup at password
        print("Which website do you want to lookup the password for?")
        for keyvalue in passwords:
            print(keyvalue[0])
        passwordToLookup = input()

        for i in range (len(passwords)):
            if passwordToLookup in passwords [i][0]:
                print (password)




#The encryption key for the caesar cypher
        unencryptionKey=-16

#Caesar Cypher Encryption
    def passwordunEncrypt (encryptedMessage, key):

    #We will start with an empty string as our encryptedMessage
        unencryptedMessage = ''

    #For each symbol in the unencryptedMessage we will add an encrypted symbol into the encryptedMessage
    for symbol in encryptedMessage:
        if symbol.isalpha():
            num = ord(symbol)
            num += key

            if symbol.isupper():
                if num > ord('Z'):
                    num -= 26
                elif num < ord('A'):
                    num += 26
            elif symbol.islower():
                if num > ord('z'):
                    num -= 26
                elif num < ord('a'):
                    num += 26

            encryptedMessage += chr(num)
        else:
            encryptedMessage += symbol

        return encryptedMessage

        encrypted = passwordEncrypt("Hello world!", 16)
        passwordEncrypt(encrypted, -16)
        print(passwordunEncrypt(passwords[i][1], 16))




        ####### YOUR CODE HERE ######
        #You will need to find the password that matches the website
        #You will then need to decrypt the password

        #
        #1. Create a loop that goes through each item in the password list
        #  You can consult the reading on lists in Week 5 for ways to loop through a list
        #
        #2. Check if the name is found.  To index a list of lists you use 2 square backet sets
        #   So passwords[0][1] would mean for the first item in the list get it's 2nd item (remember, lists start at 0)
        #   So this would be 'XqffoZeo' in the password list given what is predefined at the top of the page.
        #   If you created a loop using the syntax described in step 1, then i is your 'iterator' in the list so you
        #   will want to use i in your first set of brackets.
        #
        #3. If the name is found then decrypt it.  Decrypting is that exact reverse operation from encrypting.  Take a look at the
        # caesar cypher lecture as a reference.  You do not need to write your own decryption function, you can reuse passwordEncrypt
        #
        #  Write the above one step at a time.  By this I mean, write step 1...  but in your loop print out every item in the list
        #  for testing purposes.  Then write step 2, and print out the password but not decrypted.  Then write step 3.  This way
        #  you can test easily along the way.
        #


        ####### YOUR CODE HERE ######


    if(choice == '3'):
        print("What website is this password for?")
        website = input()
        print("What is the password?")
        unencryptedPassword = input()

    encryptedPassword = passwordEncrypt
    newsitepassword = [website, encryptedPassword]
    passwords.append (newsitepassword)
        ####### YOUR CODE HERE ######
        #You will need to encrypt the password and store it in the list of passwords

        #The encryption function is already written for you
        #Step 1: You can say encryptedPassword = passwordEncrypt(unencryptedPassword,encryptionKey)]
        #the encryptionKey variable is defined already as 16, don't change this
        #Step 2: create a list of size 2, first item the website name and the second item the password.
        #Step 3: append the list from Step 2 to the password list


        ####### YOUR CODE HERE ######

    if(choice == '4'): #Save the passwords to a file
            savePasswordFile(passwords,passwordFileName)


    if(choice == '5'): #print out the password list
        for keyvalue in passwords:
            print(', '.join(keyvalue))

    if(choice == '6'):  #quit our program
        sys.exit()

    if(choice == '7'):
        print ("What website password would you like to delete?")
        for keyvalue in passwords:
            print(keyvalue[0])
        passwordToDelete = input()

    for i in range (len(passwords)):
        if passwordToDelete in passwords [i][0]:
            passwords.remove

    print()
    print()
Error:
line 117 return encryptedMessage ^ SyntaxError: 'return' outside function Process finished with exit code 1
Reply


Messages In This Thread
Password Saver Project - by jhenry - Oct-10-2017, 09:27 PM
RE: Password Saver Project - by sparkz_alot - Oct-10-2017, 09:51 PM
RE: Password Saver Project - by jhenry - Oct-10-2017, 10:08 PM
RE: Password Saver Project - by sparkz_alot - Oct-10-2017, 10:26 PM
RE: Password Saver Project - by gruntfutuk - Oct-11-2017, 09:46 AM
RE: Password Saver Project - by jhenry - Oct-11-2017, 09:55 AM
RE: Password Saver Project - by gruntfutuk - Oct-11-2017, 10:28 AM
RE: Password Saver Project - by buran - Oct-11-2017, 10:33 AM
RE: Password Saver Project - by gruntfutuk - Oct-11-2017, 10:42 AM
RE: Password Saver Project - by sparkz_alot - Oct-11-2017, 12:31 PM
RE: Password Saver Project - by jhenry - Oct-12-2017, 06:38 AM
RE: Password Saver Project - by gruntfutuk - Oct-12-2017, 07:16 AM
RE: Password Saver Project - by jhenry - Oct-13-2017, 07:22 AM
RE: Password Saver Project - by gruntfutuk - Oct-13-2017, 07:35 AM
RE: Password Saver Project - by jhenry - Oct-13-2017, 08:15 AM
RE: Password Saver Project - by gruntfutuk - Oct-13-2017, 08:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python project help (Password manger using mysql) lifeofpy 2 4,798 Jul-31-2020, 06:18 PM
Last Post: deanhystad
  Python Password Saver Assignment sshellzr21 2 6,275 May-02-2020, 01:34 AM
Last Post: sshellzr21
  Password Saver Program suitec 3 9,038 Aug-17-2017, 12:26 AM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020