User login (three false chances)

#!/usr/bin/env python 
# -*- coding: utf-8 -*-
# @Time : 2018/5/6 0006 12:22
# @Author : Anthony.Waa
# @Site :
# @File : User Login (three wrong chances).py
# @Software: PyCharm

# demo1
# define user list
user_list = [
{'username': 'anthony', 'password': '123'},
{'username': 'chris', ' password': '123'},
{'username': 'alex', 'password': '123'},
{'username': 'oldboy', 'password': '123'},
]

# Definition
count = 0

while True:
# username and password
users = input("Please enter your username:")
pasws = input("Please enter your password:")

# Loop through the user list
for lists in user_list:
if lists['username'] == users and lists['password'] == pasws:
print("Login successful")
exit()
else:
print("Login failed, please log in again.")
count += 1
break
if count == 3:
print("Your username or password has been entered incorrectly more than 3 times, log out")
exit()


# ==================== ===================================================== ===============


# demo2
# Define user list
user_list = [
{'username': 'anthony', 'password': '123'},
{'username': 'chris ', 'password': '123'},
{'username': 'alex', 'password': '123'},
{'username': 'oldboy', 'password': '123'},
]

# Definition
count = 0

# Define status
flag = False

while True:
# Username and password
users = input("Please enter your username:")
pasws = input("Please enter your password:")

# Loop through the user list
for lists in user_list:
if lists['username'] == users and lists['password'] == pasws:
flag = True
else:
pass
# Judge the login status
if flag:
print("Login successful")
exit()
else:
print("Login failed , please log in again.")
count += 1
flag = False
# Determine whether the number of failures exceeds 3 times
if count == 3:
print("Your username or password has been entered incorrectly more than 3 times, log out")
exit( )

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325353517&siteId=291194637