- # -*- coding:utf-8 -*-
- # Login
- import os
- import sys
- info_list = []
- user_file = file('T:\\Python\\src\\ex1\\user.txt', 'r')
- for ele in user_file.readlines():
- user_info = ele.strip()
- info_list.append(user_info.split(';'))
- user_dict = dict(info_list)
- user_file.close()
- for i in range(3):
- user_name = raw_input('Please input username:')
- if user_name not in user_dict.keys():
- print "%s do not exist! Please input again!" % user_name
- continue
- if os.path.exists('T:\\Python\\src\\ex1\\%s.lock' % user_name):
- print '%s is locked! Please connect admin!' % user_name
- sys.exit()
- j = 0
- title = 2
- while j < title:
- passwd = raw_input('Please input your password: ')
- if passwd != user_dict[user_name]:
- print "Wrong! Please input again! \\
- You still have %d choice to try" % (title - j - 1)
- j += 1
- continue
- else:
- print "Login! Welcone to our home,%s!" % user_name
- sys.exit()
- else:
- print "Try to much! %s has been locled!" % user_name
- lock_file = file("T:\\Python\\src\\ex1\\%s.lock" % user_name, "w")
- lock_file.close()
- sys.exit()
- else:
- print "Try too much!Please try later!"
- sys.exit()
- #该片段来自于http://www.codesnippet.cn/detail/1811201615130.html
来源: http://www.codesnippet.cn/detail/1811201615130.html