Python 用户登录练习
2016-06-05 22:18
330 查看
#!/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:登录系统,输入用户名和密码,如果三次登录失败的话,将用户进行锁定
相关文章推荐
- Python-2 循环输出
- python格式化输出
- Python对象
- 使用gdb调试Python进程
- 从底层理解Python的执行
- windows下python2.7安装xlrd
- Python Flask Web 第十课 —— flask-wtf
- python 用pdb调试
- python-os/sys/subprocess
- Python之路_Day5
- 关于 Python generator(生成器)的类比
- Python全栈开发
- 通过xpath读取xml节点
- XTEA加密的Python调用
- Windows环境下实现Numpy、Scipy、Matlotlib、Scikit-learn的安装
- 从Python中readline()函数读取的一行内容中去掉换行符\n
- pip安装失败
- 119. Pascal's Triangle II [easy] (Python)
- python爬虫解决验证码的思路
- python之列表、元祖、集合、字典基础篇