服务器之家

服务器之家 > 正文

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

时间:2021-06-10 00:11     来源/作者:Hubery_Fight

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

初学Python—1

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#实现账号输错三次即锁定
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()

基本功能可以实现;

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

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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程序设计有所帮助。

原文链接:https://blog.csdn.net/sen1013293436/article/details/64545220

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
2021德云社封箱演出完整版 2021年德云社封箱演出在线看
2021德云社封箱演出完整版 2021年德云社封箱演出在线看 2021-03-15
返回顶部