zoukankan      html  css  js  c++  java
  • python实现简单的登录管理

    import json,time
    username=[]
    userpasswd=[]
    def login_success_file(name):
    try:
    f=open(r"F:/login_success_syslog.txt",'a+')
    json.dump(time.ctime()+":"+name,f)
    f.write(" ")
    except FileNotFoundError as e:
    print(e)
    def login_fail_file(name):
    try:
    f=open(r"F:login_faild_syslog.txt",'a+')
    json.dump(time.ctime() + ":",name,f)
    f.write(" ")
    except FileNotFoundError as e:
    print(e)
    def import_to_file():
    try:
    f1=open(r"F:username",'w',encoding="utf-8")
    f2=open(r"F:userpasswd",'w',encoding="utf-8")
    json.dump(username,f1)
    json.dump(userpasswd,f2)
    f1.close()
    f2.close()
    except FileNotFoundError as e:
    print(e)
    except Exception as e:
    print(e)
    def export_from_file():
    global username
    global userpasswd
    try:
    f1=open(r"F:username",'r',encoding="utf-8")
    f2=open(r"F:userpasswd",'r',encoding="utf-8")
    username=json.load(f1)
    userpasswd=json.load(f2)
    f1.close()
    f2.close()
    except FileNotFoundError as e:
    print(e)
    except Exception as e:
    print(e)
    def creat_user(name,passwd):
    export_from_file()
    if name in username:
    print("usernam has exist!")
    name=input("rewrite your username:")
    passswd=input("rewrite your userpassswd:")
    creat_user(name,passwd)
    else:
    username.append(name)
    userpasswd.append(passwd)
    return True
    def authentication(name,passwd):
    export_from_file()
    if name in username:
    index=username.index(name)
    if passwd==userpasswd[index]:
    return True
    else:
    return False
    else:
    return False
    def user_login_interface():
    function=input("登录输入login,注册输入regist:")
    if function !="login" and function != "regist":
    print("输入错误!")
    exit()
    name=input("username:")
    passwd=input("userpassswd:")
    if function=="login":
    if authentication(name,passwd)==True:
    login_success_file(name)
    print("login successfully!")
    else:
    login_fail_file(name)
    print("username or userpasswd error!")
    elif function=="regist":
    if creat_user(name,passwd)==True:
    import_to_file()
    print("regist sucessfully!")
    user_login_interface()
  • 相关阅读:
    idea控制台乱码问题解决
    部署springboot项目到云服务器的两种方式(jar+war)
    case...when...then....(else...)....end的使用小案例
    多线程学习(二)
    多线程学习(一)
    Swagger学习笔记
    Docker进阶篇
    Docker入门基础篇
    Markdown语法学习(推荐使用Typora编辑器)
    git(六)——IDEA中使用git
  • 原文地址:https://www.cnblogs.com/Mr-l/p/10227147.html
Copyright © 2011-2022 走看看