溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

使用Python怎么實現(xiàn)一個用戶登錄接口

發(fā)布時間:2021-03-09 16:38:20 來源:億速云 閱讀:177 作者:Leah 欄目:開發(fā)技術(shù)

這篇文章給大家介紹使用Python怎么實現(xiàn)一個用戶登錄接口,內(nèi)容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

python可以做什么

Python是一種編程語言,內(nèi)置了許多有效的工具,Python幾乎無所不能,該語言通俗易懂、容易入門、功能強大,在許多領(lǐng)域中都有廣泛的應(yīng)用,例如最熱門的大數(shù)據(jù)分析,人工智能,Web開發(fā)等。

Readme:

blog address:

摘要:編寫登錄接口

輸入用戶名、密碼

認證成功后顯示歡迎信息

輸錯3次后鎖定

關(guān)鍵詞:循環(huán);判斷;外部數(shù)據(jù)讀寫;列表;字典;

展望:可以結(jié)合數(shù)據(jù)庫讀寫。

codes:

# Author: Steven Zeng
'''
作業(yè)2:編寫登錄接口
輸入用戶名密碼
認證成功后顯示歡迎信息
輸錯3次后鎖定
'''
print("welcome to here")
f1=open('username.txt')
f2=open('password.txt')
f3=open('error.txt')#建立一個Demo記錄輸錯3次密碼的用戶,并對其鎖定
username_true=f1.readlines()#readlines讀取方式返回的是逐行一個元素的列表
password_true=f2.readlines()
un_error=f3.readlines()
f1.close()
f2.close()
f3.close()
UK={}
#建立一個字典形式為用戶名對密碼
for i in range(len(username_true)):
 UK[str(username_true[i])]=str(password_true[i])#注:字典的鍵必須是不可變更型數(shù)據(jù)(常用整數(shù)和字符串)
# 而鍵值可以是數(shù)字也可以是字符串
#print(un_error)
#print(un_error.count(777+'\n')
#print(UK)
count=0
while count<3:
 username = input("Please, input your username:")
 password = input("Please, input your keywords")
 if un_error.count(str(username+'\n'))>=3:
  print("Out of trying, You are Locking!")
  break
 elif str(username+'\n') in UK and str(password+'\n')==UK.get(str(username+'\n')):
  print("welcome to you, honorable customer!")
  break
 else:
  print('''Invalid customer, please try again!
  And you have {count_left1} times left!'''.format(count_left1=2-count))
  f3=open('error.txt','a')#建立一個Demo記錄輸錯3次密碼的用戶,并對其鎖定
  f3.write(username+'\n')
  f3.close()
 count += 1

使用Python怎么實現(xiàn)一個用戶登錄接口

關(guān)于使用Python怎么實現(xiàn)一個用戶登錄接口就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI