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

python一个简单的登录

时间:2016-06-14 19:22:58      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:

文件目录下有两个文件

user_name.txt

lock_file.txt

实际中可以读数据库里的信息

代码如下

 1 #encoding = utf-8
 2 import sys
 3 
 4 user_file = user_name.txt
 5 lock_file = lock_file.txt
 6 
 7 retry_count = 0
 8 retry_limit = 3
 9 
10 while retry_count < retry_limit:
11     username = raw_input(\033[32;1mUsername:\033[0m)
12     lock_check = file(lock_file)
13     for line in lock_check.readlines():
       line = line.split()
14 if username == line[0]: 15 sys.exit(%s is locked % username) 16 17 passwd = raw_input(\033[32;1mPassword:\033[0m) 18 19 f = file(user_file,rb) 20 match_flag = False 21 for line in f.readlines(): 22    user,password = line.strip(\n).split() 23 if username == user and passwd == password: 24 match_flag = True 25 break 26 f.close() 27 if match_flag == False: 28    print User unmatched 29 retry_count += 1 30 else: 31   print Welcome login Learning python 32   sys.exit(0) 33 else: 34 print Your account is lock 35 f = file(lock_file,ab) 36 f.write(username+\n) 37 f.close()

 

python一个简单的登录

标签:

原文地址:http://www.cnblogs.com/gide/p/5584862.html

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