zoukankan      html  css  js  c++  java
  • 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()

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


  • 相关阅读:
    MySQL主从复制与读写分离
    使用PHPCMS搭建wap手机网站
    phpcms v9不用下插件自己做留言板
    css关于banner图轮播的实现
    MySql和Oracle的日期转换到底有哪些不同?我们来比较一下
    CSS---解决内容过多就会出文本溢出(显示在区域外面,不换行的情况)
    dedecms 后台发布后的文章不能编辑出现一片空白的解决办法
    python常识系列11-->python发送邮件基础
    python常识系列10-->python代码注释规范
    python常识系列09-->logging模块之handlers的使用
  • 原文地址:https://www.cnblogs.com/smail-bao/p/5718994.html
Copyright © 2011-2022 走看看