Python Forum
Python Password Saver Assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Password Saver Assignment
#1
Hello all,

I have figured out the main parts of the assignment and am just trying to add the extra credit piece (add a 'delete password' function). I have done so and it works... but only if following these steps:

Program loads > select option 4 > delete a password > select 2 > check password > select 3 > add a password > select 2 or 4 > repeat or end

If I choose anything else before option 4 or if I add two passwords in a row and then try to delete a password, it deletes two passwords instead. Can you review my code and see where I went wrong? Not looking for an answer, just looking for some guidance. The only way I even got the program to delete passwords last night was from the line passwordToRemove = [i for i in websiteChoice if i in passwords]. I've tried to use del, remove, and pop functions and the program either didn't do anything or gave me ValueError: list.remove(x): x not in list error.

I am sure this is probably glaringly easy for all of you! Sorry, I am new to this!

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. Delete a password")
    print(" 5. Save password file")
    print(" 6. Print the encrypted password list (for testing)")
    print(" 7. Quit program")
    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)):                           #step 1 - loops through the list of passwords
            if passwordToLookup == passwords[i][0]:               #step 2 - checks if the name is found
                print(passwordEncrypt(passwords[i][1], -16))       #step 3 - prints out the passwords through encryption


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

        encryptedPassword = passwordEncrypt(unencryptedPassword, 16)       #step 1 - encrypts the new password
        newPassword = [website, encryptedPassword]                         #step 2 - creates a list including the website name and encrypted password
        passwords.append(newPassword)                                      #step 3 - adds the new password to the list

    
    if (choice == '4'): #delete a password

        print('Which website password do you wish to remove? ')
        for keyvalue in passwords:
            print(keyvalue[0])
        websiteChoice = input()
        passwordToRemove = [i for i in websiteChoice if i in passwords]

        for passwordToRemove in (passwords):
            passwords.remove(passwordToRemove)
        print('Your password for ' + str(websiteChoice) + ' has been successfully removed.')

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


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


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


    print()
    print()
Reply


Messages In This Thread
Python Password Saver Assignment - by sshellzr21 - May-01-2020, 01:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python for Everybody 5.2 assignment baba04201 20 175,012 Jul-25-2023, 04:15 PM
Last Post: MicaelSchutz
  Python for Everybody 3.1 assignment ramadan2099 18 46,098 Jan-23-2021, 06:27 AM
Last Post: KonohaHokage
  Password Checker Assignment mcostello 1 5,279 Nov-14-2020, 07:54 AM
Last Post: DPaul
  Coursera python for everybody 5.2 assignment SteppentigerV2 11 13,290 Oct-22-2020, 11:57 AM
Last Post: Larz60+
  Python project help (Password manger using mysql) lifeofpy 2 4,902 Jul-31-2020, 06:18 PM
Last Post: deanhystad
  [split] Python for Everybody 5.2 assignment ramadan2099 3 12,249 Jul-15-2020, 04:54 PM
Last Post: Bipasha
  Python Assignment 3 - Applied Data Science - 2.3 eyavuz21 8 5,209 Jun-06-2020, 08:59 AM
Last Post: eyavuz21
  Python for Everybody 3.3 assignment ramadan2099 7 32,066 Apr-08-2020, 06:49 AM
Last Post: DeaD_EyE
  Python for everyone course assignment 5.2 ofekx 3 8,694 Dec-23-2019, 08:41 PM
Last Post: nilamo
  [split] Python for Everybody 5.2 assignment jonchanzw 4 8,698 Oct-22-2019, 08:08 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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