Python之編寫登陸介面,python編寫介面

來源:互聯網
上載者:User

Python之編寫登陸介面,python編寫介面

1.輸入使用者名稱密碼;

2.認證成功後顯示歡迎資訊;

3.錯誤三次後,帳號被鎖定。

 

帳號檔案:user.txt 

鎖定檔案:locked.txt 

流程圖如下:

# -*- coding:utf-8 -*-# Author  Caoxlimport sysaccount_file='E:\user.txt'locked_file='E:\locked.txt'def deny_account(username):    print('您的使用者已被鎖定')    with file(locked_file,'a') as deny_f:        deny_f.write('\n'+username)def main():    retry_count=0    retry_limit=3                                   #迴圈次數    while retry_count<retry_limit:                 #使用者最多重複登陸3次        username=raw_input('請輸入您的使用者名稱:')  #引導使用者輸入使用者名稱        with file(locked_file,'r') as  lock_f:            #採用with開啟檔案,將locked_file賦值lock_f,防止忘記f.close()關閉檔案            for line in lock_f.readlines():       #迴圈遍曆每一行的內容                if len(line)==0:                  #對每一行內容進行處理                    continue                if username == line.strip():                    #利用.strip這個函數去掉分行符號,來對username進行匹配。                    sys.exit('使用者已經被鎖定!')        if len(username)==0:        #提示使用者登入時,使用者名稱不可為空!            print('使用者名稱不可為空,請重新輸入')            continue        password= raw_input('請輸入您的密碼:')    #引導使用者輸入密碼        with file(account_file,'r') as  account_f:            flag= False            for line in account_f.readlines():                user,pawd=line.strip().split()       #將使用者名稱和對應密碼進行處理                if username==user and password==pawd: #判斷使用者名稱和密碼                    print('success!')                    flag=True                    break                      #退出for迴圈        if flag==False:                       #避免使用者在三次輸入後,依然提示重新輸入。            if retry_count<2:                print('您輸入的使用者名稱或密碼有誤,請重新輸入!')            retry_count+=1        else:            print('歡迎使用者登陸成功!!')            break            # 加標誌位是為了使用者能夠成功推出整個迴圈!            deny_account(username)            #對應上面的def函數把鎖定帳號加入文檔中去if __name__ == '__main__':    main()
View Code

 

聯繫我們

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