码迷,mamicode.com
首页 > 其他好文 > 详细

Day1

时间:2018-01-31 00:48:31      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:锁定   用户   sys   exit   passwd   line   str   write   管理   

# -*- coding:utf-8 -*-
# Author:joycezhou
import os,sys,getpass
count = 0
while count < 3:
username = input("请输入用户名:")
lock_file = open(‘account_lock.txt‘,‘r+‘)
lock_list = lock_file.readlines()
for lock_line in lock_list:
lock_line = lock_line.strip(‘\n‘)
if username == lock_line:
print(‘用户名%s已经被锁定‘% username)
sys.exit(1)

user_file = open(‘account.txt‘,‘r‘)
user_list = user_file.readlines()
print (user_list)
for user_line in user_list:
(user,passwd) = user_line.strip(‘\n‘).split()
if username == user:
# print(username)
p = 0
while p <3:
print(username)
password = input("password:")
if password == passwd:
print("欢迎%s登录系统"%username)
sys.exit(1)
else:
if p != 2:
print(‘用户%s密码错误,请重新输入,还有%d机会‘ % (username,2-p))
p += 1
else:
lock_file.write(username + ‘\n‘)
sys.exit("对不起%s用户已被锁定,请联系管理员" % username)

else:
pass
else:
if count != 2:
print(‘对不起,%s 输入错误,请重新输入,您还有%d 次机会‘ % (username , 2-count))
count += 1
else:
sys.exit(‘用户%s不存在,退出‘ % username)

Day1

标签:锁定   用户   sys   exit   passwd   line   str   write   管理   

原文地址:https://www.cnblogs.com/joycezhou/p/8387639.html

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