python 登陆接口


#!/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()

感谢这位远在成都的朋友平时的指点


优质内容筛选与推荐>>
1、Oracle升级中的参数补充(r9笔记第2天)
2、C#快速剔除字符串中不合法的文件名或者文件路径字符
3、基于HTML5的WebSCADA工控移动应用
4、钉钉亮相数博会:企业级应用秀肌肉的正确姿势是什么?
5、Leetcode41FirstMissingPositive正解不是盛传的桶排序


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号