出力後の検証、検証を完了するために、アカウントのパスワードを入力し、「ログイン成功」
dic={"name":'admin', "password":'123'}
name = input(">>>user:")
password = input(">>>password:")
if name in dic["name"] and password in dic["password"]:
print("登录成功")
else:
print("登录成功")
異なるユーザがログインすることができます
dics = {
"admin": {"password": '123'},
"egon": {"password": '123'}
}
name = input(">>>user:")
password = input(">>>password:")
if name in dics and password == dics[name]["password"]:
print("登录成功")
else:
print("登录失败")
同じアカウントのロックを入力するには成功しなかった(ロックされた後、プログラムの場合の追加機能は、実行されている、ロックが自動的に5分後にアンロック)
import time
dics = {
"admin": {"password": '123'},
"egon": {"password": '123'}
}
count = 0
while True:
name = input(">>>user:")
password = input(">>>password:")
if count < 3 and name in dics and password == dics[name]["password"]:
print("登录成功")
break
else:
print("登录失败")
if count < 3:
count += 1
continue
else:
print("该账号已被锁定,五分钟后重试")
time.sleep(300)
count = 0
continue
拡張ニーズ:ユーザーがロックされた後に完了3に基づき、関係なく、プログラムが閉じられているかどうかに、すべての5分をロック
import time, os
dics = {
"admin": '123',
"egon": '123'
}
count = 1
while True:
if os.path.exists('lock.txt'):
with open('lock.txt', 'r', encoding='utf-8') as f:
ti = f.read()
if ti == '300':
print("已被锁定无法输入,五分钟后解锁")
time.sleep(int(ti))
with open('lock.txt', 'w', encoding='utf-8') as f:
f.write("0")
print("解锁成功!请输入")
name = input(">>>user:")
password = input(">>>password:")
if name in dics:
if count < 3 and password == dics.get(name):
print("登录成功")
break
else:
print("密码错误,登录失败")
if count < 3:
count += 1
else:
with open('lock.txt', 'w', encoding='utf-8') as f:
f.write("300")
print("已被锁定五分钟")
else:
print("账号不存在")