Python練習(第一周): 編寫登陸認證程式

來源:互聯網
上載者:User

標籤:python   form   orm   分享   後退   word   pen   color   ase   

基礎需求:讓使用者輸入使用者名稱密碼認證成功後顯示歡迎資訊輸錯三次後退出程式升級需求:可以支援多個使用者登入 (提示,通過列表存多個賬戶資訊)使用者3次認證失敗後,退出程式,再次啟動程式嘗試登入時,還是鎖定狀態(提示:需把使用者鎖定的狀態存到檔案裡)

代碼:
# 通過列表格儲存體使用者名稱,密碼logon_authentication = Falseuser_info = [[‘li‘, ‘123‘], [‘yong‘, ‘234‘], [‘liyong‘, ‘345‘]]logon_num = 3# 取鎖定名單lock_file = open(‘lock‘, ‘r‘, encoding=‘utf-8‘)lock_list = lock_file.read()lock_file.close()# 首次輸入使用者密碼user_name = input(‘please input your name :‘)user_pass = input(‘please input your password :‘)# 迴圈判斷使用者密碼for user_item in user_info:    if user_name == user_item[0]:        # 判斷是否在鎖定名單        if user_name in lock_list:            print(‘該使用者已被鎖定!‘)            break        # 驗證使用者密碼,重新輸入密碼須在限制次數內        for i in range(logon_num - 1):            if user_pass == user_item[1]:                print(‘登陸成功‘)                # 標誌位驗證登入結果及跳出多層迴圈                logon_authentication = True                break            else:                logon_num = logon_num - 1                print(‘密碼錯誤,您還有‘, logon_num, ‘次輸入密碼的機會‘)                user_pass = input(‘please again input your password :‘)        else:            print(‘超過三次,使用者鎖定!‘)            lock_file = open(‘lock‘, ‘a‘, encoding=‘utf-8‘)            lock_list = lock_file.write(user_name)            lock_file.close()            break    # 判斷跳出一級迴圈    if logon_authentication:        breakelse:    print(‘沒有此使用者‘)# 登入成功,進入下一級頁面if logon_authentication:    print(‘歡迎來到{user}的空間‘.format(user=user_name))
View Code

 

Python練習(第一周): 編寫登陸認證程式

聯繫我們

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