pythonで簡易ログインインタフェースを書く
1892 ワード
基本機能:ログイン、ブラックリスト入力、新規ユーザー追加
with open('user_list.txt', "r") as f_user_list,\
open('user_list_black.txt', "r") as f_user_list_black:
user_list_black = f_user_list_black.read().split(',') ## f_user_lis_bak user_list_black
user_list_dict = {} ##
for i in f_user_list:
user_list_dict.setdefault(i.split()[0], i.split()[1])
# name = input("Input your name: ") ##
count = 0
for i in range(3): ##
name = input("Input your name: ") ##
password = input("Input your password: ")
if name in user_list_black:
print("The user is locked") ##
continue
elif name in user_list_dict:
if password == user_list_dict.get(name):
print("welcome, ", name) ##
break
else:
if count == 2:
name_black_write = open('user_list_black.txt', 'a')
name_black_write.write(name + ',')
name_black_write.close()
print("the user is locked") ## 3
break
print("Password id wrong")
count += 1
else:
name_newer_write = open('user_list.txt', 'a' )
name_newer_write.write(name + " " + password + '
')
name_newer_write.close()
print("The user is new") #
break