第九天作业

import sys

import getpass

import hmac

import hashlib

import io

import json

# 保存所有用户

users = []


 

def main_menu():

    print("~ * ~" * 10)

    print("\t\t\t 1、用户注册")

    print("\t\t\t 2、用户登录")

    print("\t\t\t 3、退出系统")

    return input("请输入您的操作:")


 

def user_exists(username):

    for user in users:

        # {"username": "ljh",  "password": "1234"}

        if user.get("username") == username:

            return user

    return None


 

def reg():

    while True:

        f=open("d:/a.txt","w")

        username = input("请输入用户名称:")

        password = getpass.getpass("请输入用户密码:")

        confirm_pwd = getpass.getpass("请再次输入密码:")

        json.dump(users,open("a.txt","w"))

        f.close()

        message = username

        key = password

        # h = hmac.new(key,message,digestmod='MD5')

        # print(h.hexdigest())

        # 数据校验

        if username == None or username == "":

            print("对不起,用户名不能为空!!")

            continue

        if len(password) < 3:

            print("对不起,密码不能少于3位!!")

            continue

        if password != confirm_pwd:

            print("对不起,两次密码不一致,请重新输入!!")

            continue

        # 用户名称是否重复

        if user_exists(username) != None:

            print("对不起,该用户名称已经存在,请重新注册!!")

            continue

        # 保存用户

        user = {"username": username, "password": password}

        users.append(user)

        chioce = input("输入N/n则退出到上一个界面,否则继续注册")

        if choice == "N" or chioce == "n":

        # if choice.upper() == "N":

            break


 

def login():

    while True:

        f=open("d:/a.txt","r")

        json.load(open("d:/a.txt","r"))

        f.close()

        username = input("请输入用户名称:")

        password = getpass.getpass("请输入用户密码:")  

        user = user_exists(username)

        if user is not None:

            if user.get("password") == password:

                print("登录成功!!")

                denglu()

            else:

                print("对不起,密码错误")

        else:

            print("对不起,没有这个用户")

def denglu():

    print("~ * ~" * 10)

    print("\t\t\t 1、发布文章")

    print("\t\t\t 2、修改自己发布文章")

    print("\t\t\t 3、查找自己发布的文章")

    print("\t\t\t 4、查看的文件")

    return input("请输入您的操作:")

if __name__ == '__main__':

    while True:

        print(users)

        choice = main_menu()

        if choice == "1":

            # 注册

            reg()

        elif choice == "2":

            # 登录

            login()

        elif choice == "3":

            sys.exit()

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值