python登录接口代码_Python代码之登录接口

# -*- coding:utf-8 -*-

#Author:Mr Gan

import sys

limit_time = 3

loggin_time = 0

while loggin_time < limit_time:

user = input('\033[31;1m username:\033[0m').strip()

with open('account_lock','r') as lock_name:

for lock_line in lock_name:

if user == lock_line.strip():

print('you have been locked')

if len(user) == 0:#判断是否输入空用户名

print('username is not none')

continue

password = input('\033[31;1m password: \033[0m').strip()

with open('account', 'r') as account_name:

mathch_flag = False #设置登录认证标志位

for user_line in account_name.readlines():

username, passwd = user_line.strip().split()

if (user,password) == (username,passwd):

print('%s login success'% user)

mathch_flag = True#设置登录认证标志位

break #跳出for循环

if mathch_flag == False and loggin_time < 2: #登录认证不匹配

print('username or password error,please try again')

loggin_time += 1

else: #登录认证成功

with open('account_lock', 'a+') as f:

f.write('%s\n'% user )

print('you have been locked ')

break

代码不足之处:用户被锁定时,只是第三次输入的用户名被锁定到文件中,不符合逻辑

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值