You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4.1 KiB

🇺🇸🔍 🔰 🔐

🙅 💼, 👆 💪 ⚙️ 🇺🇸🔍 🔰 🔐.

🇺🇸🔍 🔰 🔐, 🈸 🎚 👈 🔌 🆔 & 🔐.

🚥 🚫 📨 ️, 📨 🇺🇸🔍 4️⃣0️⃣1️⃣ "" .

& 📨 🎚 WWW-Authenticate ⏮️ 💲 Basic, & 📦 realm 🔢.

👈 💬 🖥 🎦 🛠️ 📋 🆔 & 🔐.

⤴️, 🕐 👆 🆎 👈 🆔 & 🔐, 🖥 📨 👫 🎚 🔁.

🙅 🇺🇸🔍 🔰 🔐

  • 🗄 HTTPBasic & HTTPBasicCredentials.
  • ✍ "security ⚖" ⚙️ HTTPBasic.
  • ⚙️ 👈 security ⏮️ 🔗 👆 🛠️.
  • 📨 🎚 🆎 HTTPBasicCredentials:
    • 🔌 username & password 📨.
{!../../../docs_src/security/tutorial006.py!}

🕐 👆 🔄 📂 📛 🥇 🕰 (⚖️ 🖊 "🛠️" 🔼 🩺) 🖥 🔜 💭 👆 👆 🆔 & 🔐:

🆔

📥 🌅 🏁 🖼.

⚙️ 🔗 🚥 🆔 & 🔐 ☑.

👉, ⚙️ 🐍 🐩 🕹 secrets 🆔 & 🔐.

secrets.compare_digest() 💪 bytes ⚖️ str 👈 🕴 🔌 🔠 🦹 (🕐 🇪🇸), 👉🚫🔜 👷 ⏮️ 🦹 💖 á, Sebastián.

🍵 👈, 👥 🥇 🗜 username & password bytes 🔢 👫 ⏮️ 🔠-8️⃣.

⤴️ 👥 💪 ⚙️ secrets.compare_digest() 🚚 👈 credentials.username "stanleyjobson", & 👈 credentials.password "swordfish".

{!../../../docs_src/security/tutorial007.py!}

👉 🔜 🎏:

if not (credentials.username == "stanleyjobson") or not (credentials.password == "swordfish"):
    # Return some error
    ...

⚙️ secrets.compare_digest() 🔜 🔐 🛡 🆎 👊 🤙 "🕰 👊".

👊

"⏲ 👊"

➡️ 🌈 👊 🔄 💭 🆔 & 🔐.

& 👫 📨 📨 ⏮️ 🆔 johndoe & 🔐 love123.

⤴️ 🐍 📟 👆 🈸 🔜 🌓 🕳 💖:

if "johndoe" == "stanleyjobson" and "love123" == "swordfish":
    ...

▶️🙍 🐍 🔬 🥇 j johndoe 🥇 s stanleyjobson, 🔜 📨 False, ↩️ 💭 👈 📚 2️⃣ 🎻 🚫 🎏, 💭 👈 "📤 🙅‍♂ 💪 🗑 🌅 📊🎂 🔤". & 👆 🈸 🔜 💬 " 👩‍💻 ⚖️ 🔐".

⤴️ 👊 🔄 ⏮️ 🆔 stanleyjobsox & 🔐 love123.

& 👆 🈸 📟 🔨 🕳 💖:

if "stanleyjobsox" == "stanleyjobson" and "love123" == "swordfish":
    ...

🐍 🔜 ✔️ 🔬 🎂 stanleyjobso 👯‍♂️ stanleyjobsox & stanleyjobson🤔 👈 👯‍♂️ 🎻 🚫 🎏. 🔜 📨 🔙 " 👩‍💻 ⚖️ 🔐".

🕰 👊

👈 ☝, 👀 👈 💽 📏 📨 " 👩‍💻 ⚖️ 🔐" 📨, 👊 🔜 💭 👈 👫 🤚 🕳 ▶️️, ▶️ 🔤 ▶️️.

& ⤴️ 👫 💪 🔄 🔄 🤔 👈 🎲 🕳 🌖 🎏 stanleyjobsox 🌘 johndoe.

"🕴" 👊

↗️, 👊 🔜 🚫 🔄 🌐 👉 , 👫 🔜📋 ️, 🎲 ⏮️ 💯 ⚖️ 💯 💯 📍 🥈. & 🔜 🤚 1️⃣ 🔤 🕰.

🔨 👈, ⏲ ⚖️ 📆 👊 🔜 ✔️ 💭🆔 & 🔐, ⏮️ "ℹ" 👆 🈸, ⚙️ 🕰 .

🔧 ⏮️ secrets.compare_digest()

👆 📟 👥 🤙 ⚙️ secrets.compare_digest().

📏, 🔜 🎏 🕰 🔬 stanleyjobsox stanleyjobson 🌘 🔬 johndoe stanleyjobson. & 🎏 🔐.

👈 🌌, ⚙️ secrets.compare_digest() 👆 🈸 📟, 🔜 🔒 🛡 👉 🎂💂‍♂ 👊.

📨

⏮️ 🔍 👈 🎓 , 📨 HTTPException ⏮️ 👔 📟 4️⃣0️⃣1️⃣ (🎏 📨 🕐 🙅‍♂ 🎓 🚚) & 🚮 🎚 WWW-Authenticate ⚒ 🖥 🎦 💳 📋 🔄:

{!../../../docs_src/security/tutorial007.py!}