I'm trying to work with a PostgreSQL database I have locally, and for some odd reason the program is able to login and make changes to the database without any username or password. I have done this same process in JavaScript and it required the username and password.
Either way, isn't it extremely strange that this simple python script can use the database without any credentials? Code below.
import psycopg2
user = "";
pw = "";
conn = psycopg2.connect("dbname='log_to_db' user='" + user + "'
host='localhost' password='" + pw + "'")
cur = conn.cursor()
cur.execute("SELECT * from logs WHERE id=132")
print (cur.fetchall())
conn.close()
So, this script displays a row in the table. If anyone can help me understand why it's gaining access into the database without credentials (in addition to what I need to do to fix it), I would really appreciate it!
select user;select userit showed me a user that requires a password. I do not understand how it works without a password.pg_hba.confusing thefindutility. on mine, its inside the directory/etc/postgresql/10/main. On mac, if you install via brew, I think the file ends up in the child of/usr/local/Cellar/postgresql//usr/local/var/postgres. By default it defines "trust" for "local" (Unix socket) and "localhost" (127.0.0.1). Note that "localhost" is not in any way network accessible. Change the METHOD column to "md5" to enforce password auth.