Chinaunix首页 | 论坛 | 博客
  • 博客访问: 86885
  • 博文数量: 26
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 250
  • 用 户 组: 普通用户
  • 注册时间: 2015-08-12 22:31
文章分类

全部博文(26)

文章存档

2016年(26)

我的朋友

分类: Python/Ruby

2016-11-15 22:13:47


点击(此处)折叠或打开

  1. #_*_ coding:utf-8 _*_
  2. import os, sys
  3. if os.path.isfile('user.txt'):
  4.     pass
  5. else:
  6.     sys.exit("\033[31m没有定义用户文件\033[0m")
  7. user_li = []
  8. with open('user.txt') as f1:
  9.     for i in f1:
  10.        user = i.strip('\n').split(':')
  11.        user_li.append(user)
  12. #print(user_li)

  13. def user_name(): #用户名列表
  14.     user_n = []
  15.     for name in user_li:
  16.         user_n.append(name[0])
  17.     return user_n

  18. def user_passwd(): #密码列表
  19.     user_pass = []
  20.     for passwd in user_li:
  21.         user_pass.append(passwd[1])
  22.     return user_pass

  23. if __name__ == '__main__':
  24.     while True:
  25.         user_na = input('请输入用户名:')
  26.         username = user_na.strip()
  27.         password = input('请输入密码:')
  28. # password = input('请输入密码:')
  29.         if username in user_name():
  30.             location = user_name().index(username)
  31.             while int(user_li[location][2]) < 3:
  32.                 if password == user_li[location][1]:
  33.                     print ("\033[32m登录成功\033[0m")
  34.                     sys.exit(0)
  35.                 else:
  36.                     location = user_name().index(username)
  37.                     user_li.insert(location,[username,user_li[location][1],str(int(user_li[location][2])+1)])
  38.                     user_li.pop(location+1)
  39.                     # print(user_li)
  40.                     with open('user.txt','w+') as f1:
  41.                         for i in user_li:
  42.                             s1 = ':'.join(i)
  43.                             f1.write(s1+'\n')
  44.                     print ("\033[31m账户名或密码错误\033[0m")
  45.                     break
  46.             else:
  47.                 print ("\033[31m账户已经锁定,请联系管理员!\033[0m")
  48.                 sys.exit(0)
  49.         else:
  50.             print ("\033[31m账户名或密码错误\033[0m")
  51. else:
  52.        print ("go out")


cat user.txt
yn:yn123:0
tom:123456:0




阅读(1308) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~