Chinaunix首页 | 论坛 | 博客
  • 博客访问: 213652
  • 博文数量: 25
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 238
  • 用 户 组: 普通用户
  • 注册时间: 2015-05-11 10:03
个人简介

linux运维

文章分类

全部博文(25)

文章存档

2017年(5)

2016年(2)

2015年(18)

我的朋友

分类: Python/Ruby

2017-02-16 18:29:26


点击(此处)折叠或打开

  1. #!/usr/bin/env python
  2. # -*- conding:utf-8 -*-
  3. # Author : QiuMeng

  4. '''
  5. 模拟登陆
  6. 1.用户输入账号密码进行登陆
  7. 2.用户信息存在文件内
  8. 3.用户密码输错三次后锁定用户
  9. '''

  10. try_times = 0
  11. forbidden_user = []

  12. file = open("lock","r")
  13. for line in file:
  14.     forbidden_user.append(line.strip())
  15. file.close()

  16. username = input("Please input your username:")
  17. if username in forbidden_user:
  18.     print("You are locked!")
  19. else:
  20.     while try_times < 3:
  21.         password = input("Please input your password:")
  22.         status = False
  23.         user_info = open("db","r")
  24.         for line in user_info:
  25.             if username == line.strip().split()[0] and password == line.strip().split()[1]: #用户密码匹配,去除换行符影响
  26.                 status = True
  27.                 break
  28.             else:
  29.                 status = False
  30.                 continue # 当行判断失败后判断下一行
  31.         if status:
  32.             print("Welcome login {name}".format(name=username))
  33.             break #成功后跳出while
  34.         else:
  35.             print("username or password invalid!Please try again..")
  36.         try_times += 1 #尝试次数累计
  37.         user_info.close()
  38.     else:
  39.         file = open("lock","a")
  40.         file.write(username+'\n')
  41.         file.close()
  42.         print("You tried so many times,locked")


阅读(1599) | 评论(0) | 转发(0) |
0

上一篇:python操作redis

下一篇:python练习-三级菜单

给主人留下些什么吧!~~