import sys
import os
userf = open(‘login.txt‘)
userfr = userf.readlines()
useradd = []
password = []
unlock =[]
for line in userfr:
u = line.split()[0]
p = line.split()[1]
un = line.split()[2]
useradd.append(u)
password.append(p)
unlock.append(un)
print u,p,un
while True:
xz = raw_input(‘\033[32;1mplease xuanze 1 or 2 ,1 is locking user,2 is login in: \033[0m‘).strip()
if xz == ‘1‘:
while True:
h = 0
b = 0
xc = raw_input(‘\033[35;1myou need to choose user to locking: or e to break\033[0m‘)
if xc ==‘e‘:break
for line in useradd:
if xc == line:
xcc = raw_input(‘\033[35;1myou sure to choose locking:y or n? \033[0m‘)
if xcc == ‘y‘:
unlock[useradd.index(line)] = ‘locking‘
b = 1
break
elif xcc == ‘n‘:break
else:continue
h+=1
if h == 3: print ‘\033[33;1mplease retry to user\033[0m‘
if b == 1: break
elif xz == ‘2‘:
while True:
n = 0
m = 0
add = raw_input(‘\033[32;1mplease input you name: \033[0m‘).strip()
for line in useradd:
if add == line:
if unlock[useradd.index(line)] == ‘unlocking‘:
print ‘\033[31;1m%s is unlocking\033[0m‘ %line
break
for i in range(3):
passwd = raw_input(‘\033[32;1mplease input you passwd: \033[0m‘).strip()
if passwd == password[useradd.index(line)]:
print ‘\033[32;1mwelcome to loginx\033[0m‘
sys.exit()
n+=1
if n==3:
unlock[useradd.index(line)] = ‘unlocking‘
m +=1
if m == 3 : print ‘\033[33;1mplease retry again\033[0m‘
if add==‘exit‘:
userf.close()
userf = open(‘login.txt‘,‘w‘)
userf.truncate()
for line in range(len(useradd)):
userf.write(useradd[line])
userf.write(‘\t‘)
userf.write(password[line])
userf.write(‘\t‘)
userf.write(unlock[line])
userf.write(‘\n‘)
userf.close()
sys.exit()
else:print ‘\033[33;1mretry again\033[0m‘
n = 0
m = 0
add = raw_input(‘\033[32;1mplease input you name: \033[0m‘).strip()
for line in useradd:
if add == line:
if unlock[useradd.index(line)] == ‘unlocking‘:
print ‘\033[31;1m%s is unlocking\033[0m‘ %line
break
for i in range(3):
passwd = raw_input(‘\033[32;1mplease input you passwd: \033[0m‘).strip()
if passwd == password[useradd.index(line)]:
print ‘\033[32;1mwelcome to loginx\033[0m‘
sys.exit()
n+=1
if n==3:
unlock[useradd.index(line)] = ‘unlocking‘
m +=1
if m == 3 : print ‘\033[33;1mplease retry again\033[0m‘
if add==‘exit‘:
userf.close()
userf = open(‘login.txt‘,‘w‘)
userf.truncate()
for line in range(len(useradd)):
userf.write(useradd[line])
userf.write(‘\t‘)
userf.write(password[line])
userf.write(‘\t‘)
userf.write(unlock[line])
userf.write(‘\n‘)
userf.close()
sys.exit()
else:print ‘\033[33;1mretry again\033[0m‘
原文地址:http://bluechen.blog.51cto.com/8739192/1698888