-3

I made a program which stores, updates, removes passwords for different accounts. However, although the program runs smoothly, whenever I restart the program, the PASSWORDS dictionary gets reset to the value in the program. Is there a way to update the dictionary every time I use the program from Windows CMD?

from sys import *
from pyperclip import *

if argv[1] == 'CamelCase':
    print('Entering program')
else:
    print('Enter correct password for program')
    exit()

PASSWORDS = {'email': 'F7minlBDDuvMJuxESSKHFhTxFtjVB6',
'blog': 'VmALvQyKAxiVH5G8v01if1MLZF3sdt',
'luggage': '12345'}


if len(argv) < 2:
    print('No account named')
    exit()

action = argv[2]
account = argv[3]
if len(argv) == 5:
    password = argv[4]
else:
    pass

if action == 'check':
    if account in PASSWORDS:
        print('The account exists.\nDo you want the password.\nEnter y / n')
        response = input()
        if response == 'y':
            copy(PASSWORDS[account])
            print('Password for ' + account + ' copied to clipboard.')
            exit()
        elif response == 'n':
            print('Closing the program')
            exit()
        else:
            print('Closing program due to invalid response')
            exit()
if action == 'copy':
    copy(PASSWORDS[account])
    print('Password for ' + account + ' copied to clipboard.')
    exit()
elif action == 'add':
    PASSWORDS[account] = password
    print('Password for ' + account + ' has been added')
    exit()
elif action == 'remove':
    PASSWORDS.pop(account)
    print('Password for ' + account + ' has been removed')
    exit()
elif action == 'update':
    PASSWORDS[account] = password
    print('Password for ' + account + ' has been updated')
    exit()

2 Answers2

0

You need to use file (such as:text file) or database. Store your values here and read from here. If you want to store data that won't be removed after closing your program then this is the key trick. Simplest one is to use file.You can read this documentation to know how to use files in Python.

Taohidul Islam
  • 5,246
  • 3
  • 26
  • 39
-1

You need to check the answers here: How to save a dictionary to a file?

If you have a realy big password list and/or you want to run this code in parallel, running in more instances in the same time, you may consider using some database or other backend.

n3ko
  • 377
  • 3
  • 8
  • If the answers in one question would answer this one, flag it as a duplicate. Don't repost the same link. – Makoto Jun 24 '18 at 15:08
  • Good job Makoto. So you can mark it duplicate? So do it please. Sorry for posting link, but i have to do it again: https://meta.stackexchange.com/questions/118124/where-on-earth-is-the-mark-duplicate-ui So how the hell i should mark the duplicate if there is no link for it?! – n3ko Jun 24 '18 at 15:10