0

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)
Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
  • This is not related to Selenium, you'll have to look into a good method for hashing and storing passwords in Python, when you have that then you'll have the password to use it anywhere you want – Ayoub_B Apr 20 '18 at 13:00
  • Possible duplicate of: https://stackoverflow.com/questions/7014953/i-need-to-securely-store-a-username-and-password-in-python-what-are-my-options – Ayoub_B Apr 20 '18 at 13:00

1 Answers1

0

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'])

Elroy Jetson
  • 938
  • 11
  • 27