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

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

时间:2016-04-16 22:45:27      阅读:184      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!