Requirements Description:
First, there are two files, the first one to store the login username and password, the second to store the locked user
User is locked and cannot log in after 5 consecutive error passwords are entered
Code implementation:
#!/usr/bin/env python#_*_coding:utf-8_*_print "********************** Welcome to the landing screen *** ' Login_name = raw_input (' Please enter login name: ') name_file = file ('/users/sean /python/d1/login/name_list ', ' RB ') name_passwd_list = []name_list = []passwd_list = []luck_name_file = file ('/users/sean/python/d1/login/luck_name ', ' RB ') luck_name_list = []i = 0# loop out each line in the file, put it in the Name_passwd_list list For line in name_file.readlines (): name_ Passwd_list.append (Line.strip (' \ n ')) Name_file.close () #循环出每个用户, put it in the Name_list list while true:if i < len (name_passwd_list): Name_list.append (Name_passwd_list[i].split () [0]) i = i + 1else:break# loops out each user's password and puts it in the Passwd_list list I = 0while true:if i < len (name_passwd _list):p Asswd_list.append (Name_passwd_list[i].split () [1]) i = i + 1else:break # Loop the locked user out and put it in the Luck_name_file list FOr lineb in luck_name_file.readlines (): Luck_name_list.append (Lineb.strip (' \ n ')) luck_name_ File.close () luck_name_file_write = file ('/users/sean/python/d1/login/luck_name ', ' a ') # Determine whether the input user exists in the user list name_list if login_name in name_list:login_name_index = name_ List.index (login_name) #判断用户是否被锁定if login_name.strip () in luck_name_list:print ' user has been locked, Please change your login account. ' else:passwd_number = 0# determine if the password is correct, if input 5 times, jump out of the loop while true:if passwd_number < 5: Passwd = raw_input (' Please enter password for user%s: ' %login_name ') passwd_number = passwd_number + 1if passwd == passwd_list[login_name_index]:p rint ' Congratulations, the landing was successful! ' breakelse:print ' Sorry, the password is wrong, please Cha Zheng after landing! ' Else:luck_name_file_write.write ('%s\n '%login_name) luck_name_file_write.close () print ' user%s has more than 5 password validations in one minute, Please contact the backend administrator! ' %login_namebreakelse:print ' login name does not exist, please check the login name and try to login again! ‘
This article is from the "Loyalty" blog, make sure to keep this source http://xinsir.blog.51cto.com/5038915/1752585
Python Login Interface