day 17 作业

3.作业: 登录注册系统

import json

def all_password():

    with open('./mima.json', 'w', encoding='utf-8') as f1:
        all_password1 = json.load(f1)
        return all_password1

#登录
def sigin():
    while True:
        id1 = input('请输入账号: ')
        password1 = input('请输入密码: ')
        password = all_password()
        if id1 not in password[id1]:
            print('账号不存在,请重新输入')
            return
        if password1 != password[id1]:
            print('密码输错误')
            return
        if password1 == password[id1]:
            print('登录成功')
            return

#注册
def register():

    id1 = input('请输入账号: ')
    password1 = input('请输入密码: ')

    password = all_password()

    if id1 in password:
        print('账号已经存在,请重新输入')
        return

    password[id1] = password1
    with open('./mima.json','w',encoding='utf-8') as f1:
        json.dump(password,f1)
    if password[id1] == password1:
        print('注册成功')


def stu_system():

    while True:

        print('============================')
        print('                            ')
        print('  1.   登  录                ')
        print('  2.   注  册                ')
        print('  3.   退  出                ')
        print('                             ')
        print('============================')
        num = input('请选择1-3:     ')

        if num == '1':
            sigin()
            pass


        if num == '2':
            register()
            pass

        if num == '3':
            return  # 退出

stu_system()
import json


class Sign_in:  # 注册
    while True:
        all_password = []

        def __init__(self,id1,password):
            self.id1 = input('请输入账号: ')
            self.password = input('请输入密码: ')

            all_password = []
            id1_password = {self.id1 : self.password}
            all_password.append(id1_password)


        def register(self):  #添加到本地文件

            with open('./mima.json', 'w', encoding='utf-8') as f:
                json.dump(all_id1_password, f)


class Register:  # 登录w
    while True:

        def register(self, id1, password):
            while True:
                self.sign_in()
                #判断是否和系统的密码匹配
                for key in f:
                    if key == self.id1 and f[key]==  self.password:
                        print('   登录成功   ')

                    elif key != self.id1:
                        print('没有该账号请重新输入')
                        return
                    elif f[key] != self.passwore:
                        print('密码输错误,请重新输入')
                        return

            

class Student_system:
    while True:
        def stu_system(self):
            print('============================')
            print('                            ')
            print('  1.   登  录                ')
            print('  2.   注  册                ')
            print('  3.   退  出                ')
            print('                             ')
            print('============================')
            num = input('请选择1-3:     ')

            if num == '1':
                self.registe()


            if num == '2':
                pass  # 注册

            if num == '3':
                return  # 退出


stu = Student_system()
stu.stu_system()

你可能感兴趣的:(day 17 作业)