• 编写登陆接口


    -输入用户名密码

    -认证成功后显示欢迎信息

    -输错三次后锁定

    # -*- coding: utf-8 -*-
    #this is make sure that linux to find the language to run the program
    #!/usr/bin/env python 
    
    
    #读取文件
    def checkName(fileName,username):
        with open(fileName) as lines:
            for line in lines:
                line = line.strip()
              #print u"读取的数据为;%s"  % (line)
                if username == line:
                    return True 
    
    #在末尾写入字符
    def writeName(fileName,username):
        file = open(fileName,"a")  
        file.write(username + "
    ") 
        print u"该用户名:%s  已经被锁定!" % (username)
        file.close()
    
    
    count=0
    username = "aaa"
    pwd = "bbb"
    while count < 3:
        username = raw_input('please input username:')
        pwd = raw_input('please input pwd:')
        flag = checkName("usernameFile.txt",username)
        if flag:
            print u'该用户名已经被锁定!'
            break
        else:
            if username == 'alex' and pwd == 'alex':
                print 'Hello %s' % (username)
                break
            else:
                count += 1
                continue    
    else:  
        writeName("usernameFile.txt",username)

     

    -------------------------------------------------------------------------------------------------

     

    QQ群:871934478

     

    版权所有,转载请注明源地址                          

     

    -------------------------------------------------------------------------------------------------

     

     

  • 相关阅读:
    BZOJ3064: Tyvj 1518 CPU监控
    BZOJ3160: 万径人踪灭
    BZOJ3527: [Zjoi2014]力
    BZOJ2194: 快速傅立叶之二
    FFT模板
    Splay树再学习
    POJ2406 Power Strings KMP算法
    POJ2752 Seek the Name,Seek the Fame KMP算法
    POJ3461 Oulipo KMP算法
    POJ2004 Mix and build Trie树? dp?
  • 原文地址:https://www.cnblogs.com/yiliangmi/p/11415667.html
Copyright © 2020-2023  润新知