0

I'm trying to write a python application that must connect to a Postgres database.

I'm trying to use psycopg2 for this. Here's my connection:

connection = psycopg2.connect(user="username",
    password="password",
    host="1.6.2.1",
    port="5432",
    database="mydatabase",
    sslmode='require')

My problem is that I can't save the password in my code or in any kind of properties file or anywhere else that someone could view it.

As a Java developer, I'm used to using Jasypt and saving an encrypted password string in my application.properties. The entry looks like this:

spring.datasource.password=ENC(udfrtIm1ypnfWTTOb29mt2IzvTTZsgwi)

Is there any way I can use this particular string in my Python application or do something similar in Python?

runnerpaul
  • 5,942
  • 8
  • 49
  • 118
  • Does this answer your question? [How do I specify a password to 'psql' non-interactively?](https://stackoverflow.com/questions/6405127/how-do-i-specify-a-password-to-psql-non-interactively) – mustaccio Mar 03 '23 at 13:19
  • Thanks @mustaccio, but no. The issue isn't where the password is set, whether that be in the code, a properties file or environment variable etc. The issue is that it can't be anywhere where people could potentially view it. It should be encrypted in some way like what's done with Jasypt. – runnerpaul Mar 03 '23 at 13:30

0 Answers0