python作业之用户登录
2017-07-06 14:26
197 查看
实现一个用户登陆的小程序,如果密码错误,可以重试三次,如果三次均错误,则锁定数据库如下格式,分别用户名|密码|锁定,其中锁定字段0为正常,1为被锁定
root|admin123|0 admin|admin123|1 Cevin|admin123|0代码如下
username = input("please input your username:") file_db = open('db','r',encoding='utf-8') file = open('db','r',encoding='utf-8') test_list = []for line in file: f = line.strip().split('|') test_list.append(f[0]) file.close()if username in test_list: for line in file_db: list_db = line.strip().split('|') if list_db[0] == username and list_db[2] == '0': password = input("please input your password:") if list_db[1] == password: print('welcome %s login.' %(username)) break else: print("password is error") for i in range(4): if i == 3: print("%s is already locked" % (username)) file_db = open('db','r',encoding='utf-8') file_new_db = open('new-db','w',encoding='utf-8') for line in file_db: if username in line: test_list = line.strip().split('|') file_new_db.write(test_list[0]+ '|' + test_list[1] +'|' + '1' + '\n') else: file_new_db.write(line) file_new_db.close() file_db.close() break else: option = input("do you want do to tyr?") if option == 'no': print("ByeBye") break else: password = input("please input your password:") if list_db[1] == password: print("yes,you have already login success!") break else: print("password is error") elif list_db[0] == username and list_db[2] == '1': print("%s is already locked" %(username)) break else: passelse: print("%s is not register" %(username))
相关文章推荐
- Python小作业一(用户登录交互界面)
- Python 用户登录验证的小例子
- python django 用户注册验证登录。。。
- python 用户登录, 锁定。多用户
- python作业1.1,编写登录模块
- jsp内置对象作业1-用户登录
- 2008删除没有数据库用户映射的登录及该登陆对应的作业
- python—指定日期,从用户登录列表中找出用户该日期最可能的地理位置
- Window上python开发--4.Django的用户登录模块User
- 用Python实现web端用户登录和注册功能的教程
- python学习系列之python装饰器基础(3)---装饰器实现用户登录验证
- Python 用户登录验证的小例子
- 简明Python教程(四)———用户登录验证
- 计划任务:此任务要求指定的用户帐户以批处理作业权限登录
- Python 用户登录验证(类的继承)
- 用Python实现用户登录接口
- Python 实现简单的用户注册和登录
- 【python】实例-用户登录系统
- 初学Python-搞了一个linux用户登录监测小工具
- Python 显示LinkedIn用户作业