第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在Python中鏈接用戶名和密碼

在Python中鏈接用戶名和密碼

炎炎設(shè)計(jì) 2024-01-04 10:08:52
我編寫(xiě)了一段練習(xí)代碼,要求用戶從這個(gè)模擬數(shù)據(jù)庫(kù)中輸入用戶名和密碼。我的問(wèn)題是如何使任何給定用戶的用戶名與密碼相關(guān)聯(lián)?所以用戶“amy”的密碼將是“apple”。我是否只需要一個(gè)變量設(shè)置作為字典,或者類(lèi)似的東西?list= ["amy", "chris", "jake"]password = ["apple", "orange", "date"]login = ("")counter = 0attempts = 5out_of_attempts = Falsewhile login not in list and not (out_of_attempts):    if counter < attempts:        login = input ("enter username: ")        counter += 1    else:        out_of_attempts = Trueif out_of_attempts:        print ("Sorry login limit exceeded please try again later")else:        pass        while login not in password and not (out_of_attempts):        if counter < attempts:            login = input ("now password please: ")            counter += 1        else:            out_of_attempts = True                if out_of_attempts:        print ("sorry password limit exceeded, try again later")else:    print ("thank you please wait")
查看完整描述

3 回答

?
慕絲7291255

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊

是的,字典設(shè)置會(huì)更好:

auth = {'amy': 'apple'....

等等。代碼修改不會(huì)那么難。獲取用戶的密碼(也可以使用它來(lái)設(shè)置)

auth[login]


查看完整回答
反對(duì) 回復(fù) 2024-01-04
?
偶然的你

TA貢獻(xiàn)1841條經(jīng)驗(yàn) 獲得超3個(gè)贊

您的用戶名/密碼的等效“映射”可以如下完成:


credentials = {

    'amy': 'apple',

    'chris': 'orange',

    'jake': 'date',

}

這些允許您快速“檢查”,例如:(username in credentials返回True或False)查看用戶名是否有密碼;credentials[username]使用等獲取給定用戶名的密碼。


查看完整回答
反對(duì) 回復(fù) 2024-01-04
?
MMMHUHU

TA貢獻(xiàn)1834條經(jīng)驗(yàn) 獲得超8個(gè)贊

簡(jiǎn)單、稍微安全的方式,讓您存儲(chǔ)的不僅僅是密碼


import hashlib


db = {}


hash = lambda x: hashlib.md5(x.encode()).hexdigest()


def register(user, password, mail):

    db[user] = {"password": hash(password), "mail": mail}


def login(user, password):

    if db[user]["password"] == hash(password):

        print("success!")

    else:

        print("fail")


register("ironkey", "password123", "example@example.com")


login("ironkey", "password")

login("ironkey", "password123")


# get credentials for the user ironkey

print(db["ironkey"])

fail

success!

{'password': '482c811da5d5b4bc6d497ffa98491e38', 'mail': 'example@example.com'}


查看完整回答
反對(duì) 回復(fù) 2024-01-04
  • 3 回答
  • 0 關(guān)注
  • 180 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)