import random


# 验证码函数
def generate_checkcode(n):
    KEY = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    code = ''
    for i in range(n):
        ran = random.randint(0, len(KEY) - 1)
        code += KEY[ran]
    return code


def login():
    i = 0
    while i < 3:
        username = input('输入用户名:')
        password = input('输入密码:')
        code = generate_checkcode(5)
        print('验证码是:', code)
        code1 = input('输入验证码:')
        if code.lower() == code1.lower():
            if username == 'admin' and password == '123456':
                print('登陆成功')
                break
            else:
                print('用户名或密码错误!')
                i += 1
        else:
            print('验证码输入有误!')
            i += 1


login()
Last modification:April 20th, 2020 at 09:57 am
如果觉得我的文章对你有用,请随意赞赏