-1

My assessment is to construct a password vault, with basic python lists, functions while loops, etc, but am having issues on the part where the user actually inputs passwords for their apps. The first problem is when they ask to see their passwords and don't have any it should say "you have nothing stored", it says this but don't stop repeating it, and also wondered if I could get some help on completing the rest of it. here is what I would like this part of the code to look like in terms of using it.

Press: 1) find your existing passwords 2) save a new password for your apps 3) see a summary of your password locker 4) exit password locker successfully 2

Name of website: Facebook

Username of site: bob91

password of site: bob95

would you like to add another app: yes

Name of website: Instagram

Username of site: albert91

password of site: albert95

would you like to add another app: no

Press: 1) find your existing passwords 2) save a new password for your apps 3) see a summary of your password locker 4) exit password locker successfully 1 Which app password would you like to access: Facebook Facebook

username: bob91

password: bob95

-------------------------------------------------- My actual code right now -->


vault_apps = []           
app_name = ""
def locker_menu_func():
    print('''You have opened the locker, 
Please select what you would like to do,''')
    while True:
        locker_menu_var = input('''Press: \n1) find your existing passwords \n2) save a new password for your apps
3) see a summary of your password locke \n4) exit password locker successfully
---------------------------------------------------------------------------------
''')
        print('''----------------------------------------------------------------''')
        if locker_menu_var == "1":
            while len(vault_apps) < 1: 
                print('''you have nothing stored''') 
                break
            break
        elif locker_menu_var == "2":
            app_name = input('''
What is the name of the website/app your are adding?
''')
            app_password = input('''What is the password of your {} account?
'''.format(app_name))
            vault_apps.append([app_name, app_password])
            while True: another_app = input('''Would you like to add another app to your password locker?''')
            if another_app in {"Y", "YES"}:
                    print("okay")
                    break    

            break        

locker_menu_func()
roobo
  • 5
  • 4
  • 1
    A while repeats things but you only want it once, therefore replace `while len(app_passwords) < 1` by `if len(app_passwords) < 1`. Then you can include the `break` in the if-block. – Michael Butscher Apr 01 '19 at 04:25
  • In your `while Len(app_passwords) <1:` you have no way to update your `app_passwords` so you have created an infinite loop. Indent the `break` below there to fix that issue. – BenT Apr 01 '19 at 04:26
  • @BenT, done that bit works now, thanks, could you help with the rest im kind of stuck – roobo Apr 01 '19 at 04:28
  • 1
    You should try this on your own and you can ask then if you have a specific problem. – Michael Butscher Apr 01 '19 at 04:30
  • @Michael Butscher i have tried for 2 days actually I dont know wherer to start and how to do it, like how to append the website,username and password into a list and then show to the user when they ask – roobo Apr 01 '19 at 04:32
  • Try storing the values into a dictionary and check out this [question](https://stackoverflow.com/questions/23450680/storing-username-and-password-into-a-dictionary). – BenT Apr 01 '19 at 04:38
  • These are basic things, you should either work through the [Python tutorial](https://docs.python.org/3/tutorial/) or maybe you got other learning material from your instructor. – Michael Butscher Apr 01 '19 at 04:40
  • @Michael Butscher its an asignment their is no other material, and the material he gave us will hardly help me with this – roobo Apr 01 '19 at 04:45

1 Answers1

1

I used dictionary to store the password. Try it this way. If it solved your problem, Kindly upvote and make it as a answer.

app_passwords = {}

def locker_menu_func():
    print('''You have opened the locker, 
Please select what you would like to do,''')

    while True:
        locker_menu_var = input('''Press: \n1) find your existing passwords \n2) save a new password for your apps
3) see a summary of your password locke \n4) exit password locker successfully''')
        if locker_menu_var == "1":
            while len(app_passwords) < 1: 
                print('''you hve nothing stored''')           
                break
            else:
                for kv in app_passwords.items():
                    a=  kv[0],kv[1]
                    print(str(a).replace("(","").replace(")","").replace("[","").replace("]",""))
                #print (app_passwords)

        elif locker_menu_var == "2":
            web = input("Enter Website")
            username = input("Enter username")
            password = input("Enter password")
            app_passwords[web]=["username:"+username+","+"password:"+password]
        elif locker_menu_var == "3":
            print ("Count of Websites stored",len(app_passwords))
        elif locker_menu_var == "4":
            break


locker_menu_func()
Smack Alpha
  • 1,828
  • 1
  • 17
  • 37
  • hi thanks for your help, when you print the accountit print like this, {'facebook': ['username:bob41,password:bob42']} is there anyway to make it present better, like without all the brackets? – roobo Apr 01 '19 at 05:51
  • Edited based on your comment – Smack Alpha Apr 01 '19 at 06:07
  • I really appreciate your help,, I really haven't learnt dictionary code yet, do you think you could use lists instead, cause even my teacher will wonder how I did this, also after the user has made one account can you make it so that it asks if he want another code, I have dited my actually code which I will update now, if you don't mind helping me to maybe fix it? – roobo Apr 01 '19 at 06:12
  • I am just solving your problem and not doing your entire task. If you wanna do your task, Go with Stackoverflow or your teacher and find the solutions. With the help of Google, you can do it easily. Try it yourself – Smack Alpha Apr 01 '19 at 06:31
  • obviously, I can do it myself, I wouldn't be on here if id I didn't try myself, but sometimes trying yourself don't mean you can complete it I have googled already, been on here for the past 2 days and cant find anything that actualy make my code work, I cant ask the teacher or the highest mark I can get is an achived or in the American system a "d" – roobo Apr 01 '19 at 06:39