码迷,mamicode.com
首页 > 编程语言 > 详细

python 登陆接口

时间:2016-07-29 17:11:58      阅读:281      评论:0      收藏:0      [点我收藏+]

标签:

#!/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 登陆接口

标签:

原文地址:http://www.cnblogs.com/smail-bao/p/5718994.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!