简体   繁体   English

Python + Selenium:如何不以纯文本格式存储密码

[英]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.

相关问题 如何在python脚本中保护纯文本密码 - How to secure plain text Password in python script 如何在Django中将纯文本转换为哈希密码 - How to convert plain text to hashed password in django 如何使用 Selenium 和 Python 将文本发送到密码字段 - How to send text to the Password field using Selenium and Python 如何使用 bcrypt 将纯文本密码与散列密码进行比较? - How to compare plain text password to hashed password using bcrypt? 如何在Selenium和Python中存储文本以及用于元素搜索 - How to store text, and use for an element search, in Selenium and Python 如何使用 Selenium WebDriver 将复制的文本存储到 Python 中的变量中 - How to store copied text into a variable in Python using Selenium WebDriver Selenium + Python:将文本存储在变量中并打印 - Selenium + Python: Store text in a variable and print Python Selenium。 如何使“Keys”属性起作用? 如何在网站页面上查找纯文本? 如何自动将页面ID更改为下一个? - Python Selenium. How to make the “Keys” attribute work? How to find plain text on a site page? How to change page id to next automatically? 密码字段以纯文本显示密码 - password field is showing password in plain text 如何在Python中将%uXXXX代码转换为纯文本? - How to convert %uXXXX code to plain text in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM