简体   繁体   中英

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. But I don't want to store the password in a plain text .py file. 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'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM