本文实例为大家分享了用户登录系统python实现代码,供大家参考,具体内容如下
注意事项:
1、使用python3执行程序。按提示输入1或2,登录或退出程序
2、输入用户名后,如果用户名被锁定及无效用户名,程序会退出,请确保输入正确。
3、输入用户名正确后,输入密码。用户名正确的情况下,密码连续输错三次,用户将被锁定,禁止登录系统
#!/usr/local/env python #coding:utf-8 #Auto:Panwenbin #function: lock_file=open('file_lock.txt','r+') user_pass=open('username_file.txt','r+') count=0
cmd=input(''' 1:登录系统 2:退出系统 请输入您的操作:''') if cmd.isdigit() and int(cmd)==2: exit() elif cmd.isdigit() and int(cmd)==1: while count <3:#只要重试不超过3次就不断循环 username=input('请输入您的用户名:') for i in lock_file.readlines(): #判断用户名是否在锁文件中 i=i.split() if username in i[0]: print('对不起 %s 已锁定'%username) exit()
match = False for j in user_pass.readlines(): user,password = j.strip('\n').split() #去掉每行多余的\n并把这一行按空格分成两列,分别赋值为user,passwd两个变量 if username == user: #判断输入的用户是否存在 passwd=input ('请输入密码:') if password == passwd: print ('用户名和密码正确') match = True break elif password != passwd:#在用户名正确的前提下,判断输入的密码是否正确 for i in range(2): passwd=input ('密码错误,请重新输入密码:') if password == passwd: print ('用户名和密码正确') match = True break
if username != user :#判断用户不存在 print('您输入用户名不存,程序已退出') exit() elif match == False :#如果match还为False,代表上面的循环中跟本就没有match上用户名和密码 print('密码和用户名不匹配,尝试超过三次,用户被锁定') lock_file.write('%s \n'%username) lock_file.close() user_pass.close() exit() elif match==True: print('登录成功') break else: print('无效选项,程序已退出')
以上就是本文的全部内容,希望对大家学习python程序设计有所帮助。
更多python用户登录系统相关文章请关注PHP中文网!

Arraysinpython,尤其是Vianumpy,ArecrucialInsCientificComputingfortheireftheireffertheireffertheirefferthe.1)Heasuedfornumerericalicerationalation,dataAnalysis和Machinelearning.2)Numpy'Simpy'Simpy'simplementIncressionSressirestrionsfasteroperoperoperationspasterationspasterationspasterationspasterationspasterationsthanpythonlists.3)inthanypythonlists.3)andAreseNableAblequick

你可以通过使用pyenv、venv和Anaconda来管理不同的Python版本。1)使用pyenv管理多个Python版本:安装pyenv,设置全局和本地版本。2)使用venv创建虚拟环境以隔离项目依赖。3)使用Anaconda管理数据科学项目中的Python版本。4)保留系统Python用于系统级任务。通过这些工具和策略,你可以有效地管理不同版本的Python,确保项目顺利运行。

numpyarrayshaveseveraladagesoverandastardandpythonarrays:1)基于基于duetoc的iMplation,2)2)他们的aremoremoremorymorymoremorymoremorymoremorymoremoremory,尤其是WithlargedAtasets和3)效率化,效率化,矢量化函数函数函数函数构成和稳定性构成和稳定性的操作,制造

数组的同质性对性能的影响是双重的:1)同质性允许编译器优化内存访问,提高性能;2)但限制了类型多样性,可能导致效率低下。总之,选择合适的数据结构至关重要。

到CraftCraftExecutablePythcripts,lollow TheSebestPractices:1)Addashebangline(#!/usr/usr/bin/envpython3)tomakethescriptexecutable.2)setpermissionswithchmodwithchmod xyour_script.3)

numpyArraysareAreBetterFornumericalialoperations andmulti-demensionaldata,而learthearrayModuleSutableforbasic,内存效率段

numpyArraySareAreBetterForHeAvyNumericalComputing,而lelethearRayModulesiutable-usemoblemory-connerage-inderabledsswithSimpleDatateTypes.1)NumpyArsofferVerverVerverVerverVersAtility andPerformanceForlargedForlargedAtatasetSetsAtsAndAtasEndCompleXoper.2)

ctypesallowscreatingingangandmanipulatingc-stylarraysinpython.1)usectypestoInterfacewithClibrariesForperfermance.2)createc-stylec-stylec-stylarraysfornumericalcomputations.3)passarraystocfunctions foreforfunctionsforeffortions.however.however,However,HoweverofiousofmemoryManageManiverage,Pressiveo,Pressivero


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

记事本++7.3.1
好用且免费的代码编辑器

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器