验证账号

#!/usr/bin/env python 
# -*- coding:utf-8 -*-
def shouye():
    flag = int(input("注册请输1,登入请输2,退出请输其他键:"))
    if flag == 1:
        zhuce()
    elif flag == 2:
        login()
    else:
        exit()
    return flag

i =2
def login():
    global i
    username = input("请输入你的账号:")
    if len(username)<6 or len(username)>15:
        print("账号错误!")
        shouye()
    with open("./temp.txt","r",encoding="utf-8") as f:
        text = f.read()
    try:
        if text.find("用户名是:"+username) != -1:
            password2 = input("请输入你的密码:")
            index = int(text.index(username))
            password = text[int(text.index(username)):]
            start = password.index("密码是:",index) + 4
            end = password.index("\n", start)
            password = password[start:end]
            if password == password2:
                print("登录成功!")
            else:
                print("密码错误!您还有{}次机会".format(i))
                i = i - 1
                if i == 0 :
                    print("账号被冻结!")
                    return()
                shouye()
        else:
            print("该账号还未注册!或是账号错误!")
            shouye()
    except:
        print("该账号还未注册!或是账号错误!")
        shouye()
def zhuce():
    username = input("请输入你的账号:")
    password1 = input("请输入你的密码,密码需要在6到15位之间:")
    password2 = input("请确认你的密码:")
    while  not password1 == password2:
        print("两次密码不一致!")
        shouye()

    if len(password1)>15 or len(password1)<6:
        print("密码需要在6到15位之间!")
        shouye()
    email = input("请输入邮箱:")
    with open("./temp.txt","a",encoding="utf-8") as f:
        f.write("用户名是:"+username+"\n")
        f.write("密码是:" + password1 + "\n")
        f.write("邮箱是:" + email + "\n")
        f.write("="*50+"\n")
    print("注册成功!")
    shouye()
shouye()

你可能感兴趣的:(验证账号)