zoukankan      html  css  js  c++  java
  • 用户登录

    使用Python写的用户登录程序

    #!/usr/bin/env python
    # _*_coding:utf-8_*_
    # date:2016-7-27
    
    import time
    f = open("data")  # 打开文件
    lines = f.readlines()    # 读取文件
    num = len(lines)         # 列表内的元素个数
    count = 0
    error = 0
    while count == 0:
        user_input = input("please input the user(q or Q exit login):")
        if user_input.lower() == 'q':
            break
        pass_input = input("please input the password:")
    
        for i in range(num):
    
            line1 = lines[i]     # 列表的元素赋给line1
    
            line1_new = line1.strip('
    ')  # 去除列表里每一个元素的结尾
    
            line_new = line1_new.split(':')  # 以:为分割线进行字符串的分割使用户名和密码分开
    
            if line_new[0] == user_input and line_new[1] == pass_input:  # 如果用户名和密码匹配就登录成功
                print('''---------------------------
            登录成功
    ---------------------------''')
                count = 1
                break
    
            # 如果用户名和密码只匹配上一项就提醒用户检查自己的输入
            elif line_new[0] == user_input and line_new[1] != pass_input:
                print("check your password ")
                error += 1
    
                break
            # 如果最后一个都没有匹配到就输出没有此用户
            while i == num-1 and line_new[0] != user_input:
                print('no user')
                i = -1
        while error == 3:     # 错误3次直接锁定
            print('you are locked 3 minutes')
            time.sleep(180)    # 锁定3分钟
            error = 4
    
    f.close()
  • 相关阅读:
    python基础学习-无参装饰器
    python基础学习-day16==课后作业练习(函数对象和闭包)
    python基础学习-函数闭包
    python基础学习-函数对象与函数嵌套
    4.15作业
    反射、元类
    Mixins、多态、绑定方法与非绑定方法
    propety装饰器、继承
    封装
    4.8作业
  • 原文地址:https://www.cnblogs.com/wspblog/p/5711598.html
Copyright © 2011-2022 走看看