酸洗和隐藏密码的提示

时间:2018-01-11 22:36:32

标签: python encryption

我是python的新手并且可以使用一些帮助,我创建了一个密码锁柜程序来存储和调用各种帐户的帐户,登录和密码,这需要1个密码才能查看所有存储的信息。这是我的第一个涉及pickle模块的程序,可以使用一些输入来提高我使用它的效率,还有一种方法来增加存储信息的加密,这样就不会在pickle文件中看到单词。谢谢!

这就是我的目标。

#! python3

import sys
import pickle

PIK = "pickle.pkl"

account = []

login = []

password = []    

print('What is your password?')
while True:
    p = input() 
    if p == 'springtime':
        break
    else:
        print('Incorrect password')
        continue

while True:
    try:
        with open(PIK, 'rb') as f:
            f.close()
            break
    except FileNotFoundError:
        with open(PIK, 'ab') as f:
            pickle.dump(account, f)
            pickle.dump(login, f)

            pickle.dump(password, f)
            f.close()
            break

with open(PIK, 'rb') as f:      
    while True:
        try:           
            account = pickle.load(f)

            login = pickle.load(f)
            password = pickle.load(f)
        except EOFError:
            break


def add():
    while True:
        print('What type of account is this? CANCEL to menu')
        y = input()
        if y.lower() == 'cancel':
            menu()
            break
        elif y.lower() != 'cancel':
            print('Are you sure this is the account type?(y/n): ' + y)
            confirm = input()
            if confirm.lower() == 'y':
                account.append(y)
                break
            else:
                continue

    while True:
        print('What is the login for the account? CANCEL to menu')
        x = input()
        if x.lower() == 'cancel':
            menu()
            break

        elif x.lower() != 'cancel':
            print('Are you sure this is the login?(y/n): ' + x)
            confirm = input()
            if confirm.lower() == 'y':
                login.append(x)
                break
            else:
                continue

    while True:    
        print('What is the password for the account? CANCEL to menu')
        z = input()
        if z.lower() == 'cancel':
            menu()
        elif x.lower != 'cancel':
            print('Are you sure this is the password?(y/n): ' + z)
            confirm = input()
            if confirm.lower() == 'y':
                password.append(z)
                print('Would you like to create another account?(y/n)')
                answer = input()
                if answer.lower() == 'y':
                    add()
                    break
                elif answer.lower() == 'n':
                    with open(PIK, 'ab') as f:
                        pickle.dump(account, f)
                        pickle.dump(login, f)
                        pickle.dump(password, f)
                        f.close()
                        menu()
                        break                   
        elif confirm.lower() == 'n':
            menu()
            break


def delete():
        snap()
        print('What account would you like to delete? (1-100) CANCEL to menu')
        selection = input()
        if selection.lower() == 'cancel':

            menu()
        else:
            try:
                result = int(selection)-1
                del account[result]
                del login[result]
                del password[result]
                with open(PIK, 'ab') as f:
                    pickle.dump(account, f)
                    pickle.dump(login, f)
                    pickle.dump(password, f)
                    f.close()
            except IndexError:
                print('account does not exist, try again')
                delete()     
            except ValueError:
                print('Please select account # or CANCEL')
                delete()
            print('Would you like to delete another account?(y/n)')
            d = input()
            if d.lower() == 'y':
                delete()
            elif d.lower() == 'n':
                menu()


def view():
    snap()
    menu()

def menu():
    print('Would you like to DELETE, ADD, or VIEW an account? (enter to EXIT)')
    d = input()
    if d.lower() == 'delete':
        delete()
    elif d.lower() == 'add':
        add()
    elif d.lower() == 'view':
        view()
    elif d == '':
        exit()
    else:
        menu()

def snap():
    for i in range(len(account)):
        print('\n*******', i+1, '*******\nACCOUNT: ', account[i], '\nLOGIN: ', login[i], '\nPASSWORD: ', password[i], '\n')     
menu()

0 个答案:

没有答案