Python實(shí)現(xiàn)簡(jiǎn)單登錄驗(yàn)證
本文實(shí)例為大家分享了簡(jiǎn)單的Python登錄驗(yàn)證,供大家參考,具體內(nèi)容如下
編寫登錄接口
要求:1、輸入用戶名密碼
2、認(rèn)證成功后顯示歡迎信息
3、輸錯(cuò)三次后鎖定
#coding=utf-8
__author__ = 'wangwc'
import sys,os
count = 0
locked = 0
mark_user = 0
mark_passwd = 0
#獲取路徑
def cur_file_dir():
path = sys.path[0]
if os.path.isdir(path):
return path
elif os.path.isfile(path):
return os.path.dirname(path)
#print (cur_file_dir())
path = cur_file_dir()
#print(path)
path1 = path.replace("\\",'/') + '/'
#print (path1)
#path2 = path1 + '/'
#循環(huán)輸入
while count < 3:
name = input("Username:").strip()
if len(name) == 0:
print ("Username can not be empty....")
continue
key = input("Password:").strip()
if len(key) == 0:
print("The password can not be empty!Try again...")
continue
f = open(path1 + "username.txt","r")
userlist = f.readlines()
for user in userlist:
if user.strip() == name:
mark_user = 1
f.close()
if mark_user == 1:
f = open(path1 + "%s_lock.txt" %(name),"r")
locked = int(f.readline().strip())
f.close()
else:
print ("Username or Passsord wrong....")
break
if locked == 1:
print("Sorry, the username had been locked!!!Please call the system administrator...")
else:
f = open (path1 + "%s_passwd.txt" %(name),"r")
passwd = (f.readline().strip())
if passwd.strip() == key:
mark_passwd = 1
if mark_user == 1 and mark_passwd == 1:
f = open("%s_count.txt" %(name),"w")
f.write("0")
f.close()
print("%s,welcome BABY!" %(name) )
#input('Press Enter to exit')
else:
f = open("%s_count.txt" %(name),"r")
count = int((f.read().strip()))
f.close()
count +=1
f = open("%s_count.txt" %(name),"w")
f.write(str(count))
f.close()
print ("Username or password wrong!And the username '%s' has %d more chances to retry!" %(name,3 - count))
if(count == 3):
print ("'%s' has been locked!!!" %(name))
if os.path.exists(path1 + "%s_lock.txt" %(name)):
fobj = open(path1 + "%s_lock.txt" %(name),"w")
fobj.writelines("1\n")
else:
print ("Username or password wrong!")
continue
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。
- python之Flask實(shí)現(xiàn)簡(jiǎn)單登錄功能的示例代碼
- Python 網(wǎng)絡(luò)爬蟲--關(guān)于簡(jiǎn)單的模擬登錄實(shí)例講解
- Python腳本簡(jiǎn)單實(shí)現(xiàn)打開默認(rèn)瀏覽器登錄人人和打開QQ的方法
- Python模擬登錄驗(yàn)證碼(代碼簡(jiǎn)單)
- Python的Flask框架中實(shí)現(xiàn)簡(jiǎn)單的登錄功能的教程
- python采用requests庫(kù)模擬登錄和抓取數(shù)據(jù)的簡(jiǎn)單示例
- 通過(guò)Python編寫一個(gè)簡(jiǎn)單登錄功能過(guò)程解析
相關(guān)文章
Python3.8對(duì)可迭代解包的改進(jìn)及用法詳解
這篇文章主要介紹了Python3.8對(duì)可迭代解包的改進(jìn)及用法詳解,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-10-10
Ubuntu?Server?20.04?LTS?環(huán)境下搭建vim?編輯器Python?IDE的詳細(xì)步驟
這篇文章主要介紹了Ubuntu?Server?20.04?LTS?環(huán)境下搭建vim?編輯器Python?IDE,首先是安裝配置vim-plug及安裝coc.nvim插件,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-08-08
Python實(shí)現(xiàn)多線程并發(fā)請(qǐng)求測(cè)試的腳本
這篇文章主要為大家分享了一個(gè)Python實(shí)現(xiàn)多線程并發(fā)請(qǐng)求測(cè)試的腳本,文中的示例代碼簡(jiǎn)潔易懂,具有一定的借鑒價(jià)值,需要的小伙伴可以了解一下2023-06-06
Python3之簡(jiǎn)單搭建自帶服務(wù)器的實(shí)例講解
今天小編就為大家分享一篇Python3之簡(jiǎn)單搭建自帶服務(wù)器的實(shí)例講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-06-06
對(duì)Python3中的print函數(shù)以及與python2的對(duì)比分析
下面小編就為大家分享一篇對(duì)Python3中的print函數(shù)以及與python2的對(duì)比分析,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-05-05
關(guān)于python中readlines函數(shù)的參數(shù)hint的相關(guān)知識(shí)總結(jié)
今天給大家?guī)?lái)的是關(guān)于Python函數(shù)的相關(guān)知識(shí),文章圍繞著python中readlines函數(shù)的參數(shù)hint展開,文中有非常詳細(xì)的介紹及代碼示例,需要的朋友可以參考下2021-06-06
Python與xlwings黃金組合處理Excel各種數(shù)據(jù)和自動(dòng)化任務(wù)
這篇文章主要為大家介紹了Python與xlwings黃金組合處理Excel各種數(shù)據(jù)和自動(dòng)化任務(wù)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪<BR>2023-12-12
Python機(jī)器學(xué)習(xí)之決策樹算法實(shí)例詳解
這篇文章主要介紹了Python機(jī)器學(xué)習(xí)之決策樹算法,較為詳細(xì)的分析了實(shí)例詳解機(jī)器學(xué)習(xí)中決策樹算法的概念、原理及相關(guān)Python實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-12-12
python 自動(dòng)批量打開網(wǎng)頁(yè)的示例
今天小編就為大家分享一篇python 自動(dòng)批量打開網(wǎng)頁(yè)的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-02-02

