Python代碼之登入介面,python代碼登入

來源:互聯網
上載者:User

Python代碼之登入介面,python代碼登入

# -*- coding:utf-8 -*-
#Author:Mr Gan
import sys

limit_time = 3
loggin_time = 0

while loggin_time < limit_time:
user = input('\033[31;1m username:\033[0m').strip()
with open('account_lock','r') as lock_name:
for lock_line in lock_name:
if user == lock_line.strip():
print('you have been locked')
if len(user) == 0:#判斷是否輸入空使用者名稱
print('username is not none')
continue
password = input('\033[31;1m password: \033[0m').strip()
with open('account', 'r') as account_name:
mathch_flag = False #設定登入認證標誌位

for user_line in account_name.readlines():
username, passwd = user_line.strip().split()
if (user,password) == (username,passwd):
print('%s login success'% user)
mathch_flag = True#設定登入認證標誌位
break #跳出for迴圈

if mathch_flag == False and loggin_time < 2: #登入認證不匹配
print('username or password error,please try again')
loggin_time += 1
else: #登入認證成功
with open('account_lock', 'a+') as f:
f.write('%s\n'% user )
print('you have been locked ')
break
代碼不足之處:使用者被鎖定時,只是第三次輸入的使用者名稱被鎖定到檔案中,不符合邏輯
      

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.