1. 程式人生 > >Python打怪升級Class1

Python打怪升級Class1

UC check true real 登錄 模擬登錄 class pri int

#功能:本地文件存儲之實現模擬登錄
#用戶名和密碼保存在一個文件,所存儲用戶名密碼輸錯三次鎖定
import re
def checkUser(username):
lock = open(‘lock.txt‘,)
count = 0
for line in lock:
real_username = line.rstrip("\n")
if real_username == username:
count += 1
if count == 3:
return 0
while True:
username = input("username:")
password = input("password:")
fh = open(‘user.txt‘)
lock = open(‘lock.txt‘, ‘a+‘)
for line in fh:
real_username = re.split(‘:‘,line)[0]
real_password = re.split(‘:‘,line)[1].rstrip("\n")
if real_username == username:
result = checkUser(username)
if result == 0:
print(username+" is Lock")
break
if real_password == password:
print("Good,Login Successful")
break
else:
print("Error")
lock.write(username + "\n")
break
else:
print("No have the",username)
fh.close()
lock.close()

Python打怪升級Class1