0

I have written the following code to automate some of my work. But I need to use a password when logging into the application.

This will be a py file to run in cron on server. Therefore, I can not write the password clearly.

What should I do for the password? Can you give advice?

from splinter import Browser
import smtplib
import os
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import time

with Browser('chrome') as browser:
    # Visit URL
    url = "$some_url"
    browser.visit(url)
    if browser.is_text_present("All rights reserved."):
    # fill the user pass area on startpage
        browser.fill('usernameField', 'XXUSERNAME')
        browser.fill('passwordField', 'XXpassword')
    # find the submit button on the page and click it
        button = browser.find_by_id('SubmitButton')
        button.click()
    else:
            browser.quit()
            msg_text="""<p style="color:red;"><b> ERR1 </b></p>"""
#            print("Errtext")
ayhn
  • 21
  • 6
  • 1
    How are you planning to deploy the script on the server? Directly, as a file or within an environment (e.g. Docker / Kubernetes)? For the first ones, there are Python modules that act as clients to a secret store for storing data like passwords, for the latter, secrets are given to the container as environment variable... – ingofreyer May 27 '19 at 08:31
  • directly as a file. – ayhn May 27 '19 at 10:02

1 Answers1

0

i found this. simple but it works for my case.

import keyring
service_id = 'some_app_name'
keyring.set_password(service_id, 'user', 'welcome')
password = keyring.get_password(service_id, 'user') # retrieve password
print(password)


import base64
pass1=base64.b64encode(b"welcome") 
repr = base64.b64decode(b'd2VsY29tZQ==')
secret = repr.decode('utf-8')
print(secret)
ayhn
  • 21
  • 6
  • `keyring` would work. I personally would not recommend to just rely on `base64`, since this is easily decoded. it protects you from someone who just reads the content and should not read the plain text password but it is not really hidden. I found a StackOverflow question that has quite helpful answers for your problem, though: https://stackoverflow.com/questions/7014953/i-need-to-securely-store-a-username-and-password-in-python-what-are-my-options – ingofreyer May 28 '19 at 11:17