Python3 for(用戶登錄:)
阿新 • • 發佈:2017-08-27
urn times nal con 返回 fin pla adl bre
# -*- coding: UTF-8 -*-
# Author:Chao
import getpass
#訪問用戶文件,並把所有的用戶名和密碼用字典類型存儲並返回這個列表
def user_all():
user_dict = {}
file_object = open("userinfo.txt")
try:
file_all_the_lines = file_object.readlines()
for line in file_all_the_lines:
user_dict[line.split(" ")[0]] = line.split(" ")[1].replace("\n", "")
finally:
file_object.close()
return user_dict
def login(users, user_lo):
username = input("username:")
if username in user_lo:
print("The user has benn locked!!!")
else:
if username in users:
count = 0
while count <3:
passworld = input("passworld:")
if users[username] == passworld:
print("Welcome", username)
break
else:
print("Incorrect passworld!")
count +=1
continue
else:
print("Passworld input error more than three times, the user has locked!!! ")
file_object = open("Locked.txt", ‘a‘)
try:
file_object.write(username + " ")
finally:
file_object.close()
else:
print("User name error")
def user_lock():
file_object = open("Locked.txt")
try:
user_locked = file_object.readline()
user_locked_list = user_locked.split(" ")
finally:
file_object.close()
return user_locked_list
def main():
user_locked = user_lock()
user_list = user_all()
login(user_list, user_locked)
if __name__ == ‘__main__‘:
main()
Python3 for(用戶登錄:)