#!/usr/bin/env python
import sys
name = ''
pw=''
name_num = 0
pw_num = 0
#black_list = []
with open('a.txt','r') as f:
for i in f.xreadlines():
namelist.append(i.split()[0])
pwlist.append(i.split()[1]) def name_test(input_name, namelist):
if input_name in namelist:
return True
else:
return False name = raw_input('Please input your name:')
name_num +=1
while True:
if name_test(name, namelist):
break
else:
if name_num < 3:
name = raw_input('Name is error,Please input your name again:')
name_num += 1
else:
print 'Sorry,Today you have mistyped user name three times'
sys.exit() pw = raw_input('Please input your password:')
pw_num +=1
while True:
index_pw = pwlist[namelist.index(name)]
if pw == index_pw:
print 'welcome'
break
else:
if pw_num < 3:
pw = raw_input('Passwd is error,Please input your passwd again:')
pw_num +=1
else:
print 'Sorry,Today you have to lose the wrong password three times'
sys.exit() 这里的a.txt的格式是
bao 123
zhang 456 后面还要加入黑名单的一些小程序 这里还有一个朋友给我的程序,感觉他的更加的简练,看着舒服:
#!/usr/bin/env python 
# -*- coding: utf-8 -*-
# @Time : 2016/7/29 11:46
# @Author : Big_Bao
import sys
def name_test(input_name, namelist):
if input_name in namelist:
return True
else:
print 'Name is None.'
return False def pw_test(pw ,index_pw, innerloopnumber=0):
if pw == index_pw:
print 'Welcome.'
inn = innerloopnumber+1
return inn
else:
print 'Password is None.' namelist = []
pwlist = []
with open('a.txt','r') as f:
for i in f.xreadlines():
namelist.append(i.split()[0])
pwlist.append(i.split()[1]) index_pw = []
name = ''
pw=''
name_num = 0
pw_num = 0
inloopnum = 0 name = raw_input('Please input your name:')
name_num +=1
while True:
if name_test(name, namelist):
index_pw = pwlist[namelist.index(name)]
pw = raw_input('Please input your password:')
pw_num +=1
inloopnum_ = pw_test(pw, index_pw,innerloopnumber=inloopnum)
else:
name = raw_input('Please input your name again:')
name_num +=1 if name_num ==3:
print 'You have no chance.'
sys.exit()
if pw_num==3:
print 'You have no chance'
sys.exit()
if inloopnum_==1:
sys.exit() 感谢这位远在成都的朋友平时的指点

python 登陆接口的更多相关文章

  1. python——登陆接口设计(循环方法)

    近日重新整理了登陆接口设计程序,感觉以前的代码没有注释,让园子的其他童鞋读起来比较费劲.也没有流程图和程序运行说明. 1.流程图 2.user_file.txt&lock_file.txt文件 ...

  2. python登陆接口编写

    #coding:utf-8 import getpass,sys i=0 j=0 while i<3: username=raw_input('username:') #输入用户名 life_1 ...

  3. python 作业 编写登陆接口

    # -*- coding:utf-8 -*-import os,sysfor i in range(3):#进行3次循环 blacklist = open(r"C:\Users\Pc4\De ...

  4. Python小程序之用户登陆接口

    编写登陆接口 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定 程序逻辑图: 代码: #!/usr/bin/env python #_*_ coding:UTF-8 _*_ #__author_ ...

  5. 使用 Python 编写登陆接口

    # 使用 Python 编写登陆接口# Create Date: 2017.10.31 Tuesday# Author: Eric Zhao# -*- coding:utf-8 -*-'''编写登陆接 ...

  6. python - 登陆验证的滑块接口

    -----------------  滑块接口  ----------------- 0:大体思路:点击登陆按钮的时候会进行第一次验证(滑块验证),然后访问后台滑块接口,并返回验证结果,如果滑块接口通 ...

  7. python之编写登陆接口(第一天)

    作业:编写登陆接口 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定 针对此实例写了有二种类型的脚本,略有不同,具体如下: 帐号文件account.txt内容如下: sam 123 david ...

  8. Python学习之编写登陆接口(Day1,作业一)

    作业一:编写登陆接口 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定(下次登陆还是锁定) 知识点:while循环,for循环,文件操作,if判断,列表操作 思路: 1.登陆,三次登陆失败,锁定 ...

  9. 不用框架,原生使用python做注册接口/登陆接口/充值接口的测试,做的数据/代码分离

    注意充值时候,cookie的处理方法,还是原来的三种方法 1.操作数据文件  do_exclel.py # -*- conding:utr-8 -*- #@Time :2018/11/8 22:46 ...

随机推荐

  1. 以后上午就只能这样了么-jQuery

    hi 昨天睡得不错 为什么早上还是看不进论文,宁愿做这个,也不愿认真看论文.感觉上还是下午看论文感觉要好的多.不过最近有三十多篇要看哇...管球... 1.jQuery -----jQuery常用插件 ...

  2. C# 内存信息

      Process proc = Process.GetCurrentProcess();                 Console.Write("专用工作集内存:");   ...

  3. Mysql优化系列(1)--Innodb引擎下mysql自身配置优化

    1.简单介绍InnoDB给MySQL提供了具有提交,回滚和崩溃恢复能力的事务安全(ACID兼容)存储引擎.InnoDB锁定在行级并且也在SELECT语句提供一个Oracle风格一致的非锁定读.这些特色 ...

  4. fabric批量操作远程操作主机的练习

    fabric是python的一个基于命令行的自动化部署框架,用docker开了两个容器来学习fabric. #!/usr/bin/env python #-*- coding=utf-8 -*- fr ...

  5. 关闭tomcat, 部署并启动tomcat的脚本

    /opt/tomcat/bin/shutdown.sh rm -f /opt/tomcat/webapps/ibank.war rm -rf /opt/tomcat/webapps/ibank cp ...

  6. winform程序重启

    winform程序重启的方法: private void ReStart() { string processName = System.Diagnostics.Process.GetCurrentP ...

  7. Linux 信号详解三(sleep,raise)

    sleep()函数 .sleep()函数作用:让进程睡眠 .能被信号打断,然后处理信号函数以后,就不再睡眠,直接向下执行代码 .sleep函数的返回值是剩余秒数 //sleep 函数 #include ...

  8. Eclipse设置和必装插件

    文章长期更新,主要是记录Eclipse好用的插件和规范的设置 插件篇: 1. StartExplorer. 在Eclipse内定位项目目录,和打开项目目录下的命令行,总是非常麻烦.有了这个插件以后,这 ...

  9. Java应用程序项目的打包与发行(run.bat形式)

    参考: http://www.iteye.com/topic/57312 背景: 以前一直都是在eclipse上面创建应用程序,每次要要运行的时候都要打开eclipse, 直到有个同事叫我帮忙写一个应 ...

  10. c++ 指针(二)

    函数指针 可以使用算法的地址传递给方法,传递之前要先完成以下工作 1.获取函数的地址 2.声明一个函数指针 3.使用函数指针来调用函数 1.获取函数的地址,只要使用函数名就可以 Fun2(Fun1); ...