zoukankan      html  css  js  c++  java
  • Week1-作业:用户登陆程序

    #!/usr/bin/en python
    # Author:lijun

    '''

      输入用户名密码
      认证成功后显示欢迎信息
      输错三次后锁定

    '''
    import  sys,os
    #import  getpass

    dir = os.getcwd() passfile = dir+os.sep + "passwd.txt" blacklistfile = dir + os.sep + "blacklist.txt" #读取用户名密码文件: f = open(passfile) user_passwd = {} for line in f: l = line.strip().split(",") user_passwd[l[0]] = l[1] f.close() #读取黑名单 b = open(blacklistfile) blacklist=[] for line in b: blacklist.append(line.strip()) b.close() error_count=0 while error_count<3: error_count = error_count + 1 username = input("Login username:") password = input('passwd:') if username in blacklist: print("您的用户名已经被锁定,请联系管理员。") break if username in user_passwd.keys(): if user_passwd[username] == password: print("Login successfull. Welcome!") break else: print("您输入的账户不存在,请重新输入。") if error_count == 3: if username in user_passwd.keys(): blacklist=open(blacklistfile,"a+") blacklist.writelines(" "+username) blacklist.close() print("您已累计输错三次,您的账号[%s]已经被锁定,请联系管理员." %username) else: print("您输入的账号[%s]不存在,已经累计三次输入失败,程序将退出。." %username)
  • 相关阅读:
    [levelDB] Version Manager
    [levelDB] Compaction
    <Effective Modern C++> 读书笔记
    <Effective Modern C++> 笔记-1-Deducing Type
    水塘抽样(Reservoir Sampling)问题
    【C++工程实践】条件变量
    【c++工程实践】内存模型
    【c++工程实践】智能指针
    【c++工程实践】值语义与右值引用
    分布式系统原理-CAP/2PC/3PC
  • 原文地址:https://www.cnblogs.com/pythonlee/p/9531510.html
Copyright © 2011-2022 走看看