首页 > 编程语言 > 详细

Python12期培训班-day1-登陆验证代码分享

时间:2016-04-16 22:43:16      阅读:471      评论:0      收藏:0      [点我收藏+]
 1 #!/usr/bin/env python
 2 import sys
 3 import getpass
 4 afile = afile
 5 bfile = bfile
 6 circulation_num=0  #循环次数初始基数
 7 def deny_account(username):
 8         print("This account already locked!")
 9         with open(bfile, a+) as bf:     #此处最好为a+模式,本人之前使用a模式错误账号无法写入
10             bf.write(username + \n)
11 #循环开始
12 while circulation_num<3:
13         username = input("\033[32;1mPlease input your username:\033[0m")
14         flag = False
15         with open(afile, r) as af:
16                 for line in af.readlines():
17                         user,pwd=line.strip().split()
18                         if username==user:
19                                 password=getpass._raw_input(Please input password:).strip()
20                                 if username==user and password ==pwd:
21                                     print(success!)
22                                     flag = True
23                                     break
24                                 else:
25                                      print(password error,please try again!)
26                         else:
27                             if circulation_num < 3:
28                               print(User doesn`t exist!)
29                               circulation_num += 1
30                         break
31         if flag == True:
32                 print(Welcome %s come in TG! % username)
33                 break
34 else:
35     deny_account(username)

 

Python12期培训班-day1-登陆验证代码分享

原文:http://www.cnblogs.com/carl-angela/p/5399520.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!