要安全地儲存使用者名稱和密碼組合以在cron 作業執行的Python 腳本中使用,請考慮以下事項 options:
金鑰環庫與Windows 上的CryptProtectData API 以及其他平台上的相關API 無縫整合。這樣可以使用使用者的登入憑證對資料進行加密。其簡單用法包括:
import keyring
# Define a unique namespace for your application
service_id = 'IM_YOUR_APP!'
# Set the password for a given username
keyring.set_password(service_id, 'dustin', 'my secret password')
# Retrieve the password
password = keyring.get_password(service_id, 'dustin')
要單獨儲存使用者名,請濫用 set_password 函數:
import keyring
MAGIC_USERNAME_KEY = 'im_the_magic_username_key'
# Username to store
username = 'dustin'
# Store the password and username in the keyring
keyring.set_password(service_id, username, "password")
keyring.set_password(service_id, MAGIC_USERNAME_KEY, username)
# Retrieve username and password
username = keyring.get_password(service_id, MAGIC_USERNAME_KEY)
password = keyring.get_password(service_id, username)
由於儲存在金鑰環中的項目是使用使用者憑證加密的,因此在同一使用者帳戶下執行的其他應用程式可以存取密碼。
為了增強安全性,請考慮在將密碼儲存到金鑰環之前對其進行混淆或加密。這增加了額外的保護層,防止透過自動密碼檢索意外洩漏。但是,任何有權存取腳本原始碼的人仍然有可能解密密碼。
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3