#!/usr/bin/env python
#_*_ coding:utf-8 _*_
import os
import sys
count=3
retry_count=0
account_file='/home/hello/login.txt'
lock_file='/home/hello/lock.txt'
while retry_count < count:
username=raw_input('input the username: ')
lock_check=file(lock_file)
for line in lock_check.readlines():
line=line.split()
if username == line[0]:
sys.exit('user is locked')
# print '%s is locked',username
# break
password=raw_input('input the password: ')
f=file(account_file,'rb')
match_flag=False
for line in f.readlines():
user,passwd=line.strip('\n').split(':')
if username == user and password == passwd:
print 'login successful'
match_flag=True
break
f.close()
if match_flag == True:
print 'enjoy your system'
break
elif match_flag == False:
print 'User is not matched'
retry_count +=1
# else:
# print 'enjoy your system'
else:
print 'your account is locked'
f = file(lock_file,'ab')
f.write(username)
f.close()
note:登录系统,输入用户名和密码,如果三次登录失败的话,将用户进行锁定
#_*_ coding:utf-8 _*_
import os
import sys
count=3
retry_count=0
account_file='/home/hello/login.txt'
lock_file='/home/hello/lock.txt'
while retry_count < count:
username=raw_input('input the username: ')
lock_check=file(lock_file)
for line in lock_check.readlines():
line=line.split()
if username == line[0]:
sys.exit('user is locked')
# print '%s is locked',username
# break
password=raw_input('input the password: ')
f=file(account_file,'rb')
match_flag=False
for line in f.readlines():
user,passwd=line.strip('\n').split(':')
if username == user and password == passwd:
print 'login successful'
match_flag=True
break
f.close()
if match_flag == True:
print 'enjoy your system'
break
elif match_flag == False:
print 'User is not matched'
retry_count +=1
# else:
# print 'enjoy your system'
else:
print 'your account is locked'
f = file(lock_file,'ab')
f.write(username)
f.close()
note:登录系统,输入用户名和密码,如果三次登录失败的话,将用户进行锁定
本文介绍了一个简单的用户登录系统实现,该系统通过匹配预设的用户名和密码来验证用户身份,并在连续三次登录失败后自动锁定账户以增加安全性。
289

被折叠的 条评论
为什么被折叠?



