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

python 程序1【登录接口】

时间:2015-03-03 19:01:25      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:password   welcome   correct   用户名   python   

编写登录接口

--输入用户名和密码

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

--输错三次后锁定

version-1

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

account_file = ‘account.txt‘

lock_file = ‘lock.txt‘

for i in range(3):

    username = raw_input("username: ").strip()

    password = raw_input("password:").strip()

    if len(username) !=0 and len(password) !=0:

        f = file(‘account_file‘)

        loginSuccess = False

        for line in f.readlines():

            if username == line.split()[0] and password == line.split()[1]:  #user and passwd are correct

                print "Welcome %s login my system" % username

                break

        if loginSuccess is True:    #login success

            break

    else:

        continue

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

version-2

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

import os

account_file = ‘account.txt‘

lock_file = ‘loack.txt‘


# put account in  a list

f =file(account_file)

account_list = f.readlines()

f.close()


while True:

   # put locked user into a lock list

    f = file(lock_file)

    lock_list = []

    for i in f.readlines():

        line=i.strip(‘\n‘)

        lock_list.append(line)

    f.close()

    loginSuccess = False

    userame =raw_input(‘username: ‘).strip()

    if username in lock_list:

        print "Sorry,you are already in the block list,getthe fuking out!"

        break

    for line in account_list:

        line = line.split()

        if line[0] == username:    #username correct

            for i in range(3):

                password =  raw_input(‘passwd:‘).strip()

                if password == line[1]:    #paswd correct

                    print "Welcome %s  login my system!" % username

                    loginSuccess = True

                    break            

            else:

                f = file(lock_file,‘a‘)

                f.write(‘‘%s\n‘ %username)

                print "Entered 3 times of wrong passwd,going to lock %s" % username

            if loginSuccess == True:break #jump out of the for top loop    

    if loginSuccess == True:break #jump out of the while loop 

                 

python 程序1【登录接口】

标签:password   welcome   correct   用户名   python   

原文地址:http://sailq21.blog.51cto.com/6111337/1616814

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