Python Forum
How to pass encrypted pass to pyodbc script - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to pass encrypted pass to pyodbc script (/thread-40432.html)



How to pass encrypted pass to pyodbc script - tester_V - Jul-27-2023

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