python一个简单的登录
2024-08-29 14:30:40
文件目录下有两个文件
user_name.txt
lock_file.txt
实际中可以读数据库里的信息
代码如下
#encoding = utf-8
import sys user_file = 'user_name.txt'
lock_file = 'lock_file.txt' retry_count = 0
retry_limit = 3 while retry_count < retry_limit:
username = raw_input('\033[32;1mUsername:\033[0m')
lock_check = file(lock_file)
for line in lock_check.readlines():
line = line.split()
if username == line[0]:
sys.exit('%s is locked' % username) passwd = raw_input('\033[32;1mPassword:\033[0m') f = file(user_file,'rb')
match_flag = False
for line in f.readlines():
user,password = line.strip('\n').split()
if username == user and passwd == password:
match_flag = True
break
f.close()
if match_flag == False:
print 'User unmatched'
retry_count += 1
else:
print 'Welcome login Learning python'
sys.exit(0)
else:
print 'Your account is lock'
f = file(lock_file,'ab')
f.write(username+'\n')
f.close()
最新文章
- php注释规范
- Android系统中自定义按键的短按、双击、长按事件
- ABAP中RETURN与EXIT语句的区别
- C++ 哈希表
- data source 和initial catalog
- 王立平-- ContentValues , HashTable , HashMap差别
- poj3206(bfs+最小生成树)
- Directx11学习笔记【十五】 基本几何体的绘制
- c++ lower_bound upper_bound
- mongodb入门笔记
- POJ-3421 X-factor Chains---求因子+递推 或 素因子+组合数学
- Spark技术内幕:Master的故障恢复
- AE、AS调用时用代码提供许可(不需要添加LicenseControl控件)
- heartbeat.go
- 软件工程 week 04
- 为什么浏览器User-agent总是有Mozilla字样
- 从 Secure Element 到 Android KeyStore
- php 常用$_SERVER变量列表
- HDU5387-模拟水题
- OneZero第四周第四次站立会议(2016.4.14)
热门文章
- Android自动化预备(下)
- SecureCRT自动备份脚本-华为
- 小希的数表2(用的for循环)
- Android(Xamarin)之旅(四)
- [Shell]字符截取命令:cut, printf, awk, sed
- 【Map】MapTest
- [Chapter 3 Process]Practice 3.12 Including the initial parent process, how many processes are created by the program shown in Figure 3.32?
- P1093 奖学金
- Splunk及splunkforward简单部署配置
- 改变tableView索引颜色