Enter the account password to complete the verification, verification after the output, "Login Successful"
dic={"name":'admin', "password":'123'}
name = input(">>>user:")
password = input(">>>password:")
if name in dic["name"] and password in dic["password"]:
print("登录成功")
else:
print("登录成功")
Different users can log
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("登录失败")
Unsuccessful attempts to enter the same account lock (additional functions in the case of the program has been running, once locked, the lock automatically unlock after 5 minutes)
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
Expansion needs: Based on the 3 completed once the user is locked, regardless of whether the program is closed, all locked 5 minutes
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("账号不存在")