pythonhashpasswordssplinter

How do i use password in python file?


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")

Solution

  • 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)