码迷,mamicode.com
首页 > 编程语言 > 详细

python 多用户登录

时间:2017-07-07 16:37:02      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:lease   使用   http   代码   log   退出   style   images   lock   

需求:

  • 可以支持多个用户登录 (提示,通过列表存多个账户信息)
  • 用户3次认证失败后,退出程序,再次启动程序尝试登录时,还是锁定状态(提示:需把用户锁定的状态存到文件里)

流程图:

技术分享

代码:

 1 div={
 2 list1:{password:123456},
 3 list2:{password:123456},
 4 list3:{password:123456},
 5 }
 6 f = open(black_user,r)
 7 lock_file = f.readlines()
 8 f.close()
 9 count=0
10 count1=0
11 while True:
12     name_input=input("please input name:")
13     if count == 3:
14         print("用户名输入次数到达限制")
15         break
16     if  not name_input in div:
17             print("用户名错误")
18             count +=1
19     if  name_input in lock_file:
20         print("户名已锁定,暂停使用!")
21         exit()
22 
23     if name_input in div:
24         count -=2
25         password_input=str(input("please input password:"))
26         if password_input == div[name_input][password]:
27             print ("密码成功")
28             break
29         else:
30             print("密码错误")
31             count1 +=1
32         if count1 == 2:
33             print("您输入的密码错误次数已达3次,将锁定您的账户!")
34             f = open(black_user, w)
35             f.write(%s%name_input)
36             f.close()
37             break

 

python 多用户登录

标签:lease   使用   http   代码   log   退出   style   images   lock   

原文地址:http://www.cnblogs.com/wangshaojie/p/7132663.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!