小白学Python(四) 简单的用户管理系统v0.2
来源:互联网 发布:mac下制作windowsu盘 编辑:程序博客网 时间:2024/05/16 19:36
今天趁着有兴致再来更一篇吧。今天做的是一个弱弱的用户管理系统,具有登录,退出登录,查询登录状态等简单的功能。
为什么是0.2呢,是因为这个东西还有一点小bug#不过应该随手就能改,等本白学会写网络的用户管理以后再发布一个更加完整的版本
bugs:初次使用没有创建文件的过程,加一句检查就行了
好了,废话少说,放码过来!
#user management system#made by TY L#PKU EECSimport timeimport osimport msvcrtclass User:def __init__(self, t_last_time = None, t_name = None, t_password = None):self.name = t_nameself.password = t_passwordself.last_time = t_last_timedef check(self, t_name, t_password):if self.name == t_name and self.password == t_password:return Trueelse:return Falsedef updateUserName(self, t_name):if t_name != None:self.name = t_nameelse:print("Name Error!")def updateUserPassword(self, t_password):if t_password != None:self.passworrd = t_passwordelse:print("Password Error!")def __str__(self):return self.name + ' ' + self.password + ' ' + repr(self.last_time)def login(old, new):name_ = input("Please enter your name\n>>>")pw = input("Please enter your password\n>>>")for each in old:if name_ == each.name:if pw == each.password:print("Login successfully!")each.last_time = repr(time.ctime())time.sleep(1)return each, old, newelse:print("Wrong password!")time.sleep(1)return None, old, newfor each in new:if name_ == each.name:if pw == each.password:print("Login successfully!")each.last_time = repr(time.ctime())time.sleep(1)return each, old, newelse:print("Wrong password!")time.sleep(1)return None, old, newprint("No such user!")time.sleep(1)return None, old, newdef register(old, new):name_ = ''while True:name_ = input("Please enter a user name\n>>>")for each in old:if name_ == each.name:print("User existed!")#time.sleep(1)continuefor each in new:if name_ == each.name:print("User existed!")#time.sleep(1)continuebreakpw = input("Please enter your password\n>>>")time_ = time.ctime()newUser = User(time_ ,name_, pw)new.append(newUser)print("Register successfully!")time.sleep(1)return new, newUserdef display(a_user):print("Name: " + a_user.name)print("Last time: " + repr(a_user.last_time))print("Press any key to continue...")msvcrt.getch()def mainMenu():menu = """Please select a instruction through the number:1. Login2. Register3. Display4. Logout5. Quit"""olduser = []newuser = []userfile = open("Userfile.txt", "r")for eachline in userfile:n, p, l = eachline.split(' ', 2)olduser.append(User(l, n, p))userfile.close()user = Nonewhile True:#clear screenos.system('cls')cmd = input(menu + "\n>>>")if cmd == '1':tmp, olduser, newuser = login(olduser, newuser)if tmp != None:user = tmpelif cmd == '2':newuser, user = register(olduser, newuser)elif cmd == '3':display(user)elif cmd == '4':user = Noneelif cmd == '5':breakelse:print("Invalid option, please try again!")time.sleep(1)#update dataolduser.extend(newuser)updatedUserfile = open("Userfile.txt", "w")for each in olduser:updatedUserfile.write(str(each))updatedUserfile.write('\n')def main():string = """PKU EECSTY L"""print(string)mainMenu()if __name__ == '__main__':main()
另外笔者仍然觉得可以写得更简单,希望各位前辈们指教o(* ̄▽ ̄*)ブ
0 0
- 小白学Python(四) 简单的用户管理系统v0.2
- Python--简单的用户管理系统
- jsp之简单的用户管理系统(2)
- python用户管理系统
- 机房收费系统--系统用户管理模块和主窗体的建立(四)
- python简单用户管理模拟
- Java简单用户管理系统
- Linux系统调用列表(四)用户管理
- [内存管理]管理图解v0.1 v0.2 v0.3
- 完全基于Servlet的简单用户管理系统
- 简单用户管理系统--User的设计
- mysql的用户管理(四)
- 编写一个简单的用户管理系统(工厂代理模式)
- jsp之简单的用户管理系统(4,mvc模式)
- python实现的简单用户注册登录系统
- 一步一步使用Ext JS MVC与Asp.Net MVC 3开发简单的CMS后台管理系统之用户管理(2)
- 使用Ext JS MVC与Asp.Net MVC 3开发简单的CMS后台管理系统之用户管理(2)
- redis 用户好友管理登陆简单系统
- poj 3725 稀疏矩阵剪枝快速幂
- 数组
- FS4054锂电池充电ic
- VS2010平台下VAssistX和Qt的整合配置及相关便捷操作
- php开发(一)
- 小白学Python(四) 简单的用户管理系统v0.2
- 20150810解题报告
- 数据库
- [2015-08-09] python020
- ubuntu下中文输入法的安装--fcitx
- hdu 4280 Island Transport (最大流)
- leetCode #231 Power of Two
- 送给自己的一篇文章
- HDU1233畅通工程