写的这么烂,都不好意思往出发,后来想想毕竟是第一个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执行此脚本
转载于:https://blog.51cto.com/liulidong/1773570