Python Forum

Full Version: How to pass encrypted pass to pyodbc script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Greetings to you all!
I'm trying to pull out some data from MS SQL DB.
I have to encrypt the user name and the pass, I found how to encrypt a text file and how to access my MS SQL DB but I have no idea how to put these two scripts together Sad .
Here is the encryption snippet:
#   Making the encryption key:

from cryptography.fernet import Fernet
key = Fernet.generate_key() 
print(key) # 

#   Incrypting the Password file

from cryptography.fernet import Fernet
key = b'5YBR7_2gufXlbmMg13QB9c71WR6h9m2Sq49tLwCsOVk='
cipher_suite = Fernet(key)
ciphered_text = cipher_suite.encrypt(b'Mypassword')
with open('C:/01/Python _passwords/encripted_bytes.bin', 'wb') as file_object:  file_object.write(ciphered_text)
And the DB access snipped:
import pyodbc 

conn = pyodbc.connect('DRIVER={SQL Server};SERVER=myremoteServer5.hps.com,1333;DATABASE=MYMSSQLDB;UID=aa;PWD=allgetlost')
cursor = conn.cursor()
for row in cursor.tables():
    print(row.table_name)
Any help is really appreciated.
Thank you