zoukankan      html  css  js  c++  java
  • 登录验证,错误三次锁定帐号

    需求:用户的登录验证,登录错误三次锁定用户,用户名和密码保存在文件中

    编译环境:python3

    流程图如下:

    代码如下:

    file = open('lock.txt').readlines()
    name = input("username:
    >>").strip()
    lock = []
    for i in file:
        line = i.strip('
    ')
        lock.append(line)
    if name in lock:
        print(name, "已经被锁定")
    else:
        i = 1
        while i <= 3:
            i += 1
            print('...........')
            username = name
            print(username)
            password = input('password:
    >>').strip()
            f = open('user.txt', encoding='utf-8').readlines()
            login = False
            if len(username) != 0 and len(password) != 0:  # 判断是否为合法输入
                for line in f:
                    if username == line.split()[0] and password == line.split()[1]:  # 用户名和密码匹配正确
                        print('欢迎登录')
                        login = True
                        break
                    else:
                        continue
            if login is False:
                print(u'帐号或密码错误')
            if login is True:
                        break
        else:
            f = open('lock.txt', 'a')
            f.write(name)
            f.write('
    ')
            f.close()
            print('您的密码输入错误已达三次,帐号锁定,退出')
    

      

  • 相关阅读:
    css变量
    es6的this指向
    Java面试题(包装类)
    moment笔记
    Class
    CSS斜切角
    Element.getBoundingClientRect()
    Do not mutate vuex store state outside mutation handlers.
    antd不想写那么多option怎么办
    解析URL参数
  • 原文地址:https://www.cnblogs.com/mountian-lion/p/6081234.html
Copyright © 2011-2022 走看看