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【登录接口】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: proc_open 命令包含“有小问题
- 下一篇: python 模拟抽象类