python 实现登陆接口

要求:

1、输入用户名密码

2、认证成功后显示欢迎信息

3、输入三次后,锁定账户

流程图:

代码实现:

 1 #!/usr/bin/env python
 2 #!-*- coding:utf-8 -*-
 3 #!--author:freem---
 4 import os
 5 def auths(username,password):
 6     for i in range(3): #循环3次,实现3次登陆认证
 7         user=input("please insert you username:",)
 8         pswd=input("please insert you password:",)
 9         if(user==username and pswd==password):  #判断输入用户名和密码是否跟系统用户名密码匹配
10             os.system('cls')
11             print("
")     #登陆成功!
12             print("*******************************************")
13             print("*welcome to index,you inserted is correct!*")
14             print("*******************************************")
15             break        #如果认证成功退出整个循环
16         elif(user==username):
17             print("please ensure your password!") #密码错误
18         else:
19             print("please ensure your username!")#用户名错误
20     else:
21         print("you account has been locked!") #账户被锁
22     
23 if __name__=="__main__":
24     username="freem"
25     password="123"
26     auths(username,password) #调用auths函数

实现效果:

输入三次失败,账户被锁住:

输入一次错误密码,输入正确的用户名和密码:

输入正确的用户名和密码后,显示欢迎信息!

匆匆路过的游人~不甘堕落的凡人~走走停停的伪书生……
原文地址:https://www.cnblogs.com/freem/p/5860535.html