zoukankan      html  css  js  c++  java
  • Python之路 day1 用户登录多次被锁定

    编写登陆接口:

    • 输入用户名密码
    • 认证成功后显示欢迎信息
    • 输错三次后锁定
     1 #Author:ersa
     2 import getpass,os,sys
     3 
     4 #读取账户信息到内存中
     5 try:
     6     accounts_file = open("E:/LinuxStudy32/Python/accounts.txt", "r")
     7 except IOError:
     8     print("The file don't exitst,Please double check!")
     9     exit()
    10 
    11 accounts_info = accounts_file.readlines()
    12 accounts_file.close()
    13 
    14 #write username to lock accounts file
    15 try:
    16     lock_file = open("E:/LinuxStudy32/Python/lock_accounts.txt","r")
    17 except IOError:
    18     print("The file don't exitst,Please double check!")
    19     exit()
    20 lock_users = lock_file.readlines()
    21 lock_file.close()
    22 
    23 #passwd = getpass.getpass("passwd:")
    24 
    25 count = 0
    26 
    27 while count<3:
    28     username = input("username:")
    29     passwd = input("passwd:")
    30     end_loop = 0
    31     for user in lock_users:
    32         user = user.rstrip() #除掉行末尾的空格、回车符
    33         if user == username:
    34             exit("Invalid {name},your account is locked!".format(name=username))
    35 
    36     account = username + " " + passwd
    37     for userinfo in accounts_info:
    38         userinfo = userinfo.rstrip()    #除掉行末尾的空格、回车符
    39         if userinfo == account:
    40             exit("Welcome user {name} login...".format(name=username))
    41 
    42     count += 1
    43     if count == 3:
    44         try:
    45             lock_file = open("E:/LinuxStudy32/Python/lock_accounts.txt", "a")
    46         except IOError:
    47             print("The file don't exitst,Please double check!")
    48             exit()
    49         username += "
    "
    50         lock_file.write(username)
    51         lock_file.close()
    52         print("Invalid {name},your account is lock...".format(name=username))
    53 else:
    54      print("you have tried too many times...fuck off")
    55 
    56 #print(username,passwd)
  • 相关阅读:
    国产开源软件
    Tomcat系统架构
    移动端前端常见的触摸相关事件touch、tap、swipe
    spring配置文件详解
    Java获取文件中视频的时长
    java命令行导出、导入sql文件
    Java国密相关算法(bouncycastle)
    Java中将对象转换为Map的方法
    Virtual Box虚拟机下CentOS网络设置
    VirtualBox安装虚拟机全过程
  • 原文地址:https://www.cnblogs.com/iersa/p/6182419.html
Copyright © 2011-2022 走看看