No.1Register/login

import pickle

def register():
    print("---Register---")
    print("Please input your username :")
    username = input("")
    print("Please input your password :")
    password = input("")
    dic = {username:password}
    with open('info_user', 'ab') as f:
        pickle.dump(dic,f)
    print("Register succeed!")

def log():
    print("---Log in ---")
    print("Please input your username :")
    username = input("")
    with open('info_user', 'rb') as F:
        while True:
            try :
                a = pickle.load(F)
                if list(a.keys())[0] == username:
                    print("Please input your password :")
                    password = input("")
                    if password == list(a.values())[0]:
                        print('Log in succeed!')
                    else:
                        print("Password Mistake!")
                    break
            except EOFError:
                print("Username not existed!")
                break

def main():
    print("1.注册;2.登陆")
    choice = input('')
    if choice == "1":
        register()
    elif choice == "2":
        log()
    else:
        print("重新输入!")

main()
 

猜你喜欢

转载自www.cnblogs.com/deng-fei/p/11184331.html
今日推荐