Python3 for(使用者登入:)

來源:互聯網
上載者:User

標籤:ror   for   auth   count   使用者名稱   continue   int   lis   字典   

# -*- coding: UTF-8 -*-
# Author:Chao
import getpass

#訪問使用者檔案,並把所有的使用者名稱和密碼用字典類型儲存並返回這個列表
def user_all():
user_dict = {}

file_object = open("userinfo.txt")
try:
file_all_the_lines = file_object.readlines()

for line in file_all_the_lines:
user_dict[line.split(" ")[0]] = line.split(" ")[1].replace("\n", "")

finally:
file_object.close()

return user_dict


def login(users, user_lo):
username = input("username:")

if username in user_lo:

print("The user has benn locked!!!")

else:

if username in users:

count = 0
while count <3:
passworld = input("passworld:")
if users[username] == passworld:
print("Welcome", username)
break
else:
print("Incorrect passworld!")
count +=1
continue
else:
print("Passworld input error more than three times, the user has locked!!! ")

file_object = open("Locked.txt", ‘a‘)
try:
file_object.write(username + " ")
finally:
file_object.close()
else:
print("User name error")

def user_lock():

file_object = open("Locked.txt")

try:

user_locked = file_object.readline()
user_locked_list = user_locked.split(" ")

finally:

file_object.close()

return user_locked_list

def main():

user_locked = user_lock()
user_list = user_all()
login(user_list, user_locked)

if __name__ == ‘__main__‘:
main()

Python3 for(使用者登入:)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.