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

python第一天作业 登录 三次错误 锁定账户

时间:2016-05-15 20:05:45      阅读:284      评论:0      收藏:0      [点我收藏+]

标签:用户名   password   python   touch   please   

写的这么烂,都不好意思往出发,后来想想毕竟是第一个py程序,还是在上班时间偷偷写的,拿出来做个纪念吧,

技术分享

# -*- coding:utf-8 -*-
#!/usr/bin/env python
import os
import os.path
username = "liulidong"
password = "123456"
k = 1
for i in range(10):
      if not os.path.exists(‘/tmp/lock.txt‘): # 判断词典文件是否存在
             os.system("touch /tmp/lock.txt")
      output = open(‘/tmp/lock.txt‘,‘r‘) # 打开词典文件
      read = output.read()               # 读取词典内容
      arr= read.split(‘;‘)               #以;分隔,将字符串转为数组
      user = input("please input your username: ")  # 输入用户名
      passwd = input("please input your password: ") #输入密码
      for n in range(0, len(arr)):
          if user == arr[n]:
              print("your name is lock please mail to administrator")
              os._exit(1)     #循环判断用户是否在字典中
      if username == user and password == passwd:
          print("welcome to linux")           #输入正确返回欢迎信息
          break
      else:
          k+=1
          print("your name or password is wrong")
          if k > 3:                         # 输出三次记录到文件里面
             output = open(‘/tmp/lock.txt‘,‘a‘)
             output.write(user + ‘;‘)
             output.close()
             print("you test too many,your username will be lock")
             break




请在下linux用python3执行此脚本


python第一天作业 登录 三次错误 锁定账户

标签:用户名   password   python   touch   please   

原文地址:http://liulidong.blog.51cto.com/9439411/1773570

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