当前位置: 移动技术网 > IT编程>脚本编程>Python > Python实现账号密码输错三次即锁定功能简单示例

Python实现账号密码输错三次即锁定功能简单示例

2019年06月03日  | 移动技术网IT编程  | 我要评论

九歌祭,美网奖金,慈禧变干尸

本文实例讲述了python实现账号密码输错三次即锁定功能。分享给大家供大家参考,具体如下:

初学python—1

#实现账号输错三次即锁定
user = "hubery"
passwd = "123"
confirm = 0
lock=0
fileopen = open("username.txt","a+")
fileopen.seek(0)
for i in range(3):
 username = input("username:")
 passsword = input("password:")
 for line in fileopen.readlines():
  if username == line.strip():
   print("账户已经锁定!")
   lock=1
   break
  else:
   continue
 fileopen.seek(0)
 if user == username and lock ==0:
  if passwd == passsword:
   print("欢迎,欢迎!")
   confirm = 1
   break
  else:
   print("账号户或者密码错误!")
   continue
 elif lock==1:
  continue
 else:
  print("1账号或者密码错误!")
  continue
fileopen.close()
if confirm == 0 and lock==0:
 filewrite=open("username.txt","a")
 filewrite.write(username+"\n")
 filewrite.close()

基本功能可以实现;

锁定的账号为第三次输错的用户名(待完善)

以下为完善版本,如有错误,请告知

import os
user = "hubery"
passwd = "123"
count = 0
lock = 0
fileopen = open("username.txt", "a+")
fileopen.seek(0)
while 1:
 for i in range(5):
  username = input("username:")
  passsword = input("password:")
  for line in fileopen.readlines():
   if username == line.strip():
    print("账户已经锁定!")
    lock = 1
    break
   else:
    continue
  fileopen.seek(0)
  if user == username:
   if lock == 1:
    continue
   elif passsword == passwd:
    print("欢迎,欢迎!")
    os._exit(0)
   elif count < 2:
    print("账号或者密码错误!")
    count += 1
    continue
   else:
    fileopen.write(username + "\n")
    fileopen.flush()
    print("密码输入错误超过三次,账户已经锁定!")
    fileopen.seek(0)
    continue
  else:
   print("账号密码错误!")
   continue
 check=input("还想验证其他账户?(yes-继续,no-退出)")
 if "no"==check.lower():
  os._exit(0)
 else:
  continue
fileopen.close()

更多关于python相关内容感兴趣的读者可查看本站专题:《python数据结构与算法教程》、《python编码操作技巧总结》、《python函数使用技巧总结》、《python字符串操作技巧汇总》及《python入门与进阶经典教程

希望本文所述对大家python程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网