Python Forum
How to pass encrypted pass to pyodbc script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to pass encrypted pass to pyodbc script
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to pass a mongdb command to a module and execute it. cspower 0 317 Feb-03-2024, 09:54 PM
Last Post: cspower
  Using pyodbc&pandas to load a Table data to df tester_V 3 829 Sep-09-2023, 08:55 PM
Last Post: tester_V
  How to pass -Xutf8 parametri to python tierox 2 879 Jun-07-2023, 07:17 AM
Last Post: tierox
  Pass variable to subprocess paulo79 4 10,113 Apr-12-2022, 12:35 PM
Last Post: DeaD_EyE
  pyodbc gmerritt 8 2,925 Feb-21-2022, 07:21 PM
Last Post: gmerritt
  How to pass variables from one class to another hobbyist 18 10,780 Oct-01-2021, 05:54 PM
Last Post: deanhystad
Question How to pass a method as argument in an another method? anilanvesh 6 2,754 Sep-30-2021, 10:18 PM
Last Post: deanhystad
  How to pass list of values to a API request URL chetansaip99 0 3,537 Sep-28-2021, 07:37 AM
Last Post: chetansaip99
  Regex - Pass Flags as a function argument? muzikman 6 3,617 Sep-06-2021, 03:43 PM
Last Post: muzikman
Exclamation win32com: How to pass a reference object into a COM server class Alfalfa 3 4,899 Jul-26-2021, 06:25 PM
Last Post: Alfalfa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020