日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python 登录接口_使用python编写一个登录接口

發布時間:2025/3/15 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 登录接口_使用python编写一个登录接口 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

需求:

編寫登錄接口

輸入用戶名密碼

認證成功后 顯示歡迎信息

輸入三次后鎖定

用戶信息文件

黑名單的文件

黑名單里檢查,不讓登錄

用戶名密碼判定

流程圖:

代碼:#!/usr/bin/env?python

tries?=?0

lockfile?=?open(‘account_lock.txt‘,‘r+‘,encoding=‘UTF-8‘)

tolockfile?=?open(‘account_lock.txt‘,‘a‘,encoding=‘UTF-8‘)

userfile?=?open(‘account.txt‘,‘r‘,encoding=‘utf-8‘)

def?islock(account):

for?line?in?lockfile:

line?=?line.strip(‘\n‘)

if?line?==?account:

print(‘此賬號已鎖定‘)

exit()

def?inaccount(account):

for?line?in?userfile:

col1_user,col2_pass?=?line.strip().split()

if?col1_user?==?account:

passtries?=?0

while?passtries?

pass1?=?input(‘請輸入密碼:‘)

if?col2_pass?==?pass1:

print(‘歡迎使用‘)

exit()

else:

passtries?+=1

else:

tolockfile.write(‘%s\n‘?%(account))

print(‘賬號已鎖定!‘)

exit()

else:

print(‘此賬號不存在‘)

break

while?tries<3:

account?=?input(‘請輸入賬號:‘)

islock(account)

inaccount(account)

tries?+=1

else:

print(‘此用戶真的不存在?88‘)

exit()

lockfile.close()

userfile.close()

tolockfile.close()

#?with?open(‘account_lock.txt‘,‘a‘,encoding=‘UTF-8‘)?as?data:

#?????data.write("aaa")

#此方法可以方式忘記文件close

#tolockfile?=?open(‘account_lock.txt‘,‘a‘,encoding=‘UTF-8‘)

#open文件后進行追加至最后一行

總結

以上是生活随笔為你收集整理的python 登录接口_使用python编写一个登录接口的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。