zoukankan      html  css  js  c++  java
  • 190327 Python登录接口

     1 #!Author:John
     2 # _*_ coding: utf-8 _*_
     3 #编写登录接口
     4 #输入用户名密码
     5 #认证成功后显示欢迎信息
     6 #输错三次后锁定
     7 import sys, os, getpass
     8 
     9 
    10 limit = 3
    11 count = 0
    12 account_file = "account.txt"
    13 lock_file = "locked.txt"
    14 
    15 while count < limit:
    16     username = input("Please input username:")
    17     # 打开文件后第一步输入用户名,打开lock文件,检查改用户是否已经被锁定
    18 
    19     f1 = open(lock_file,'r')
    20     # r后面不能加b,加b是以bytes类型打开,输入的用户名、密码是字符串str和bytes不匹配
    21     for line in f1.readlines():
    22         if username == line.strip():
    23             sys.exit("User %s has been locked!"%username)
    24     f1.close()
    25     password = input("Please input password:")
    26 
    27     f = open(account_file, 'r')
    28     match_flag = False
    29     for line in f.readlines():
    30         user,pwd=line.strip().split()   # 这里的知识点需要掌握
    31         if user==username and pwd == password:
    32             print(username,"has match successfully!")
    33             match_flag=True
    34             break
    35     f.close()
    36     if match_flag==False:
    37         print("Username or password is incorrect!")
    38         count+=1
    39     else:
    40         print("Welcome login Python Learning system!")
    41         break
    42 else:
    43     print("Your account has been locked!")
    44     f1=open(lock_file,"a")
    45     f1.write(username+'
    ')
    46     f1.close()
    View Code

     

  • 相关阅读:
    开通博客了
    nginx一些高级配置
    hue的优化
    hue改下载行数
    运维常用脚本
    scala
    kafka调优
    confluent部署:
    Redis主从及哨兵
    Redis配置
  • 原文地址:https://www.cnblogs.com/jakye/p/10610153.html
Copyright © 2011-2022 走看看