In this example we will show how to implement a simple login system with Python.
Source Code
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
credential = {"John" : "123a", "Jack" : "456b"}
success = False
for i in range(3):
username = input("please enter your username: ")
password = input("please enter your password: ")
if (credential.get(username) == password):
print("login succeeded")
success = True
break
else:
print("login failed")
if not success:
print("\nYour login failures have reached maxinum, please try again in 10 minutes!")
Output:
1) Input correct username and password
please enter your username: Jack
please enter your password: 123a
login succeeded
2) Re-run the program with the input of wrong username and password for 3 times
please enter your username: Jack
please enter your password: 456b
login failed
please enter your username: Kate
please enter your password: 123a
login failed
please enter your username: Peter
please enter your password: 123a
login failed
Your login failures have reached the maximum, please try again in 10 minutes!