1. 程式人生 > >Day1作業-模擬登錄

Day1作業-模擬登錄

tor elif log odin util users python vid min

# /usr/bin/env python
# -*- coding: utf-8 -*-
# Author:jenvid.yang
import getpass
import shutil
userspwd = {}
# print(type(userspwd))
userssta = {}
luser = []
count = 0
usercontent = open(‘../config/users.inf‘, ‘r‘)
for line in usercontent:
luser.append(line.rstrip(‘\n‘))
# print(luser)
usercontent.close()
pwdcontent = open(‘../config/users.pwd‘, ‘r‘)
for line in pwdcontent:
key, value = line.rstrip(‘\n‘).split(":")
userspwd[key] = value
# print(type(userspwd))
# print(userspwd)
pwdcontent.close()
stacontent = open(‘../config/users.sta‘, ‘r‘)
for line in stacontent:
key, value = line.rstrip(‘\n‘).rsplit(":")
userssta[key] = value
stacontent.close()
# print(userssta)


while count < 3:
username = input("pls input your name:")
password = getpass.getpass("pls input your password:")
# for i in luser:
judge_key = username in userssta.keys()
if judge_key and int(userssta[username]) == 3:
print("your passwod was locked,pls contact administartor")
break
elif judge_key and password == userspwd[username]:
for i in luser:
if username == i:
print("welcome login system", username)
exit(0)
# elif username==i and password!=userspwd[i]:
# print("%s password is not correct,pls reinput!",username)
# elif username==i and usersstat[i] > 3:
# print("%s password was locked, pls contact administrator!")
else:
print("your username or password is invalid,pls reinput!")
count += 1
if count == 3 and username in userssta.keys():
print("your password was locked,pls contact administartor")
stacontent = open(‘../config/users.sta‘, ‘r‘)
new_pwd = open(‘../config/users_new.sta‘,‘w‘)
for line in stacontent:
if username in line:
line = line.replace("0", "3")
new_pwd.write(line)
stacontent.close()
new_pwd.close()
shutil.move(‘../config/users_new.sta‘,‘../config/users.sta‘)

Day1作業-模擬登錄