User error three password lock user name

Source: Internet
Author: User

#!/usr/bin/env python
#author: Zhanglei

#导入模块
Import Getpass
Exit = [' Q ', ' Quit ']

#定义一个空列表
lock = []
Username = input ("Input username:"). Strip ()


#已只读的方式打开lock黑名单文件
Lock_file = open (' Lock.txt ', ' R '). ReadLines ()
For I in Lock_file:
line = I.strip (' \ n ')
Lock.append (line) #从文件读取的内容添加到lock列表内



#判断输入的用户名是否在lock黑名单里
If username in Lock:
Print ("The \033[31;5m account has been locked, please contact the Administrator!") \033[0m ")
Else
Counter = 0
While True:
Counter +=1
f = open (' User.txt ', ' R '). ReadLines () #已只读的方式打开user文件
Password = getpass.getpass () #已密文的方式输入密码
Break_flag = False #加入break_flag进行判断是否为真, true to jump out of the loop
If password in Exit:break #判断用户输入的密码是否在Exit列表内, then jump out
For I in F:
Lists = I.strip (). Split () #将文件转换为列表
If username = = Lists[0] and password ==lists[1]: #分别判断用户名密码是否和lists列表内的第一第二个元素相等
Print ("\033[35;2mwelcome login...\033[0m")
Break_flag = True
Break
Else
Continue
If Break_flag is True: #判断break_flag是否为真
Break
Else
If Len (password) ==0: #如果password变量的字符长度为0则跳出本次循环继续下一次循环 While setting the counter value to 0
Counter =0
Continue
Else
If counter ==3: #如果密码输入次数为3, the user name is locked
f = open (' Lock.txt ', ' a ') #已追加的方式打开lock文件
F.write (username+ ' \ n ')
F.flush ()
F.close ()
Print ("\033[31;5m has been entered more than three times, please unlock \033[0m")
Break

User error three password lock user name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.