python实训案例-用户账户管理

描述 具体
语言 python
题目描述 某些网站要求访问者在访问网站内容之前必须先进行登录,若访问者没有该网站的账号,则需要先进行注册。访问者注册完账号后,网站的服务器会保存账号信息,以便访问者下次访问网站可根据保存的信息验证访问者身份。未保障账户安全,访问者可时常修改账户的密码;
要求 注册,登录,修改密码,注销账号

结果:

# 用户类
class User:name = ""password = ""# Dao层数据类
# 用于和文件进行交互
class DaoDate:# 注册函数def Register(self, user):userId = user.nameuserPassword = user.passwordwith open('userFile.txt', 'r') as file:userDate = file.readline()while userDate:if userDate.split('~')[0] == userId:return FalseuserDate = file.readline()passwith open('userFile.txt', 'a+') as file:line = userId + "~" + userPasswordfile.writelines(line + "\n")return Truepass# 登录函数def Login(self, user):with open('userFile.txt', 'r') as file:message = file.readline()while message:Date_name = message.split('~')[0]Date_pass = message.split('~')[1]if Date_name == user.name:if Date_pass == user.password + "\n":return Truemessage = file.readline()return False# 修改密码def upPassword(self, user):lineList = []with open('userFile.txt', 'r') as file:lineList = file.readlines()for mes in lineList:if user.name == mes.split("~")[0]:lineList.remove(mes)lineList.append(user.name + "~" + user.password + "\n")breakpasswith open('userFile.txt', 'w') as file:passwith open('userFile.txt', 'w') as file:for i in lineList:file.writelines(i)passdef Zhuxiao(self, us):with open('userFile.txt', 'r') as ff:lineList = ff.readlines()for mes in lineList:if us.name == mes.split("~")[0]:lineList.remove(mes)breakpasswith open('userFile.txt', 'w') as file:passwith open('userFile.txt', 'w') as file:for i in lineList:file.writelines(i)pass# u = User()
# u.name = "123q"
# u.password = "45kdwjcner6"
# d = DaoDate()
# print(d.Login(u))
# d.upPassword(u)# 展示界面
def View():print("  ------欢迎来到登录界面------")print("-" * 30)print("|", " " * 11, "1.注册", " " * 8, "|")print("|", " " * 11, "2.登录", " " * 8, "|")print("|", " " * 11, "3.修密", " " * 8, "|")print("|", " " * 11, "4.注销", " " * 8, "|")print("|", " " * 11, "5.退出", " " * 8, "|")print("-" * 30)View()
flag = False
fun = int(input("请输入你的操作:"))
while fun != 5:if fun == 1:  # 进到注册界面UserId = str(input("请输入你的账号:"))UserPassword = str(input("请输入你的密码:"))u = User()u.name = UserIdu.password = UserPasswordd = DaoDate()boo = d.Register(u)if boo:print("注册成功!")else:print("注册失败!")elif fun == 2:  # 进到登录界面Login_UserId = input("请输入你的账号:")Login_UserPassword = input("请输入你的密码:")u = User()u.name = Login_UserIdu.password = Login_UserPasswordd = DaoDate()boo = d.Login(u)if boo:print("登录成功!")else:print("登录失败!")elif fun == 3:  # 进到修改密码阶段Test_UserId = input("请输入你的原始账号:")Test_UserPassword = input("请输入你的原始密码:")u = User()u.name = Test_UserIdu.password = Test_UserPasswordd = DaoDate()boo = d.Login(u)if boo:newPassword_1 = input("请输入你的新密码:")newPassword_2 = input("请再次输入你的新密码:")while newPassword_1 != newPassword_2:print("两次密码不一致,请重新输入!")newPassword_1 = input("请输入你的新密码:")newPassword_2 = input("请再次输入你的新密码:")u.password = newPassword_1d.upPassword(u)else:print("登录失败!")elif fun == 4:Test_UserId = input("请输入你要注销的账号:")Test_UserPassword = input("请输入你要注销的密码:")us = User()us.name = Test_UserIdus.password = Test_UserPasswordd = DaoDate()boo = d.Login(us)if boo:d.Zhuxiao(us)print("注销成功")else:print("注销失败!")else:print("输入无效,请重新输入!")fun = int(input("请输入你的操作:"))

python实训案例-用户账户管理相关推荐

  1. Python快速编程入门 第2版 实训案例及课后编程题

    目录 本文档仅供参考,更新了 第2章 第3章 第4章 第5章 第6章 第7章 本文档仅供参考,更新了6.7章 第2章 2.4.1打印购物小票 蚂蚁森林是支付宝客户端发起"碳账户"的 ...

  2. 红亚科技联手董付国老师开启Python实训教育新篇章

    2017年是人工智能正式上升为国家战略的元年,Python被大家评为人工智能最佳语言,其魅力已超C#,Java,C,C++,它被昵称为"胶水语言",更被热爱它的程序员誉为" ...

  3. Python实训day14am【Python网络爬虫综合大作业-答辩】

    Python实训-15天-博客汇总表 实训总结: 由浅入深的了解了python语言应用: 编写了很多案例,完成了发作业,提升了编程思路和能力: 了解了行业现状,认识到企业对人才的要求,去除焦虑,对后续 ...

  4. Python实训day10am【Python中的地址引用、os模块】

    Python实训-15天-博客汇总表 目录 1.Python中的地址引用 2.os模块(操作系统模块) 2.1.os案例1 2.2.os案例2 2.3.os案例3 2.4.os案例4 2.5.os案例 ...

  5. Python实训day09am【Pandas、Series、DataFrame数据帧】

    Python实训-15天-博客汇总表 目录 1.Pandas 1.1.安装Pandas库 1.2.两种数据对象 2.一列数据Series 2.1.获取Series与数据个数 2.2.切片-loc-il ...

  6. Python实训day07am【爬取数据接口、webdriver、自动化测试工具selenium】

    Python实训-15天-博客汇总表 目录 1.网络爬虫-课后练习题 1.1.写法1 1.2.写法2 2.Selenium自动化测试工具 2.1.安装工具 2.2.命令行操作 直接爬取HTML (30 ...

  7. Python实训-15天-博客汇总表

    目录 1.课程安排 1.1.课程介绍 1.2.课程目标 2.课件 2.1.课件and录屏 2.2.练习and案例and作业 3.实训博客笔记 第1周-week1 day01 day02 day03 d ...

  8. Android实训案例(四)——关于Game,2048方块的设计,逻辑,实现,编写,加上色彩,分数等深度剖析开发过程!...

    Android实训案例(四)--关于Game,2048方块的设计,逻辑,实现,编写.加上色彩.分数等深度剖析开发过程! 关于2048,我看到非常多大神,比方医生.郭神.所以我也研究了一段时间.还好是研 ...

  9. python实训day1

    今日作业: name=' aleX' print(name) print(name.strip()) print(name.startswith('al')) print(name.endswith( ...

  10. 构造中小型园区网实训案例

    构造中小型园区网实训案例 一.实验工具与实验拓扑规划 1.实验工具 2.实验拓扑 二.需求分析 三.数据规划 四.实施步骤 步骤1:配置所有终端 步骤2:配置所有接入层交换机 步骤3:配置网关路由器A ...

最新文章

  1. CNN网络中的 1 x 1 卷积是什么?
  2. 小米 android 刷4.0,小米如何刷MIUI4.0系统教程
  3. 操作系统(十五)调度算法的评价指标
  4. scanf返回值_IO FILE之任意读写和scanf的限制绕过
  5. 从零开始实现ASP.NET Core MVC的插件式开发(五) - 插件的删除和升级
  6. 菜鸟学Linux 第034篇笔记 vmlinuz, initrd, modules, script
  7. netcat、nc工具随记
  8. 原生JS替代jQuery的各种方法汇总
  9. 基于JAVA+SpringMVC+MYSQL的便利店运营管理系统
  10. Python Logging Handler
  11. python list排序方法_python中List的sort方法指南
  12. 深度学习自学(三十二):半监督焦点人物检测
  13. 【专题】CSDN下载频道【2月热门资源TOP100】汇总
  14. 中标麒麟使用centos源_中标麒麟操作系统yum源配置
  15. ralink网卡驱动 linux,Ralink for linux Usb无线网卡驱动编译
  16. 【零散知识】最大类间方差法(大津法,Otsu)
  17. 【游戏技术】建造防守 Build and Defense
  18. 洛谷—P1330 封锁阳光大学
  19. 直播软件系统搭建技术分享
  20. 户外P10全彩LED显示屏一站式解决方案。

热门文章

  1. 十大城市11月房价止跌回升 上海涨幅最高
  2. 简易网页版进程管理器(支持手机管理电脑进程)
  3. html5渐变色毛玻璃,基于CSS3实现的毛玻璃渐变效果
  4. PageOffice 在线打开 word 文件实现痕迹保留、键盘批注、手写批注
  5. Flutter随记四:null safe之 ??= 和??和 ?使用区别
  6. 渔业古谚语 好吃排“第五”——清蒸白姑鱼
  7. 那是什么进程 —— svchost.exe是什么? 它为何运行?
  8. apkeditor pro_APK编辑器 APK Editor Pro v1.15.0 + ApkModifier v3.6
  9. apkeditor pro_APK编辑器:APK Editor Pro
  10. Android power键亮屏流程