日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python 程序1【登录接口】

發布時間:2025/7/14 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 程序1【登录接口】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

編寫登錄接口

--輸入用戶名和密碼

--認證成功后顯示歡迎信息

--輸錯三次后鎖定

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?

?????????????????

轉載于:https://blog.51cto.com/sailq21/1616814

總結

以上是生活随笔為你收集整理的python 程序1【登录接口】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。