[英]Python + Selenium: How to not store password in plain text
I want to write a Python script that automatically logs me into a website, using Selenium. 我想编写一个Python脚本,该脚本使用Selenium自动将我登录到网站。 But I don't want to store the password in a plain text .py file.
但是我不想将密码存储在纯文本.py文件中。 What are my options?
我有什么选择? Here's the code I have so far:
这是我到目前为止的代码:
from selenium import webdriver
import time
driver = webdriver.Firefox()
website = driver.get("https://reddit.com")
uname = driver.find_element_by_name("user")
pword = driver.find_element_by_name("passwd")
button = driver.find_element_by_class_name("btn")
time.sleep(0.5)
uname.send_keys("xDinomode")
pword.send_keys("")
time.sleep(0.3)
button.click()
time.sleep(60)
One solution would be to store your passwords in a DB and hash them. 一种解决方案是将密码存储在数据库中并对其进行哈希处理。 Then, connect to said Database and retrieve the passwords.
然后,连接到所述数据库并检索密码。
You can also use environment variables and use them to reference the password without storing the plaintext password in your application. 您还可以使用环境变量并将其用于引用密码,而无需在应用程序中存储纯文本密码。
ie, 即
import os print(os.environ['SOMEPASSWORD'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.