文件目录下有两个文件

user_name.txt

lock_file.txt

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

代码如下

 #encoding = utf-8
import sys user_file = 'user_name.txt'
lock_file = 'lock_file.txt' retry_count = 0
retry_limit = 3 while retry_count < retry_limit:
username = raw_input('\033[32;1mUsername:\033[0m')
lock_check = file(lock_file)
for line in lock_check.readlines():
       line = line.split()
if username == line[0]:
sys.exit('%s is locked' % username) passwd = raw_input('\033[32;1mPassword:\033[0m') f = file(user_file,'rb')
match_flag = False
for line in f.readlines():
   user,password = line.strip('\n').split()
if username == user and passwd == password:
match_flag = True
break
f.close()
if match_flag == False:
   print 'User unmatched'
retry_count += 1
else:
  print 'Welcome login Learning python'
  sys.exit(0)
else:
print 'Your account is lock'
f = file(lock_file,'ab')
f.write(username+'\n')
f.close()

最新文章

  1. php注释规范
  2. Android系统中自定义按键的短按、双击、长按事件
  3. ABAP中RETURN与EXIT语句的区别
  4. C++ 哈希表
  5. data source 和initial catalog
  6. 王立平-- ContentValues , HashTable , HashMap差别
  7. poj3206(bfs+最小生成树)
  8. Directx11学习笔记【十五】 基本几何体的绘制
  9. c++ lower_bound upper_bound
  10. mongodb入门笔记
  11. POJ-3421 X-factor Chains---求因子+递推 或 素因子+组合数学
  12. Spark技术内幕:Master的故障恢复
  13. AE、AS调用时用代码提供许可(不需要添加LicenseControl控件)
  14. heartbeat.go
  15. 软件工程 week 04
  16. 为什么浏览器User-agent总是有Mozilla字样
  17. 从 Secure Element 到 Android KeyStore
  18. php 常用$_SERVER变量列表
  19. HDU5387-模拟水题
  20. OneZero第四周第四次站立会议(2016.4.14)

热门文章

  1. Android自动化预备(下)
  2. SecureCRT自动备份脚本-华为
  3. 小希的数表2(用的for循环)
  4. Android(Xamarin)之旅(四)
  5. [Shell]字符截取命令:cut, printf, awk, sed
  6. 【Map】MapTest
  7. [Chapter 3 Process]Practice 3.12 Including the initial parent process, how many processes are created by the program shown in Figure 3.32?
  8. P1093 奖学金
  9. Splunk及splunkforward简单部署配置
  10. 改变tableView索引颜色