-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
36 lines (31 loc) · 872 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import psycopg2
from psycopg2 import sql
def authenticate_user(username, password):
try:
conn = psycopg2.connect(
dbname="database_my",
user="db_username",
password="db_password",
host="localhost",
port="5432" #port="5001:5000"
)
cursor = conn.cursor()
query = sql.SQL(" = %s")
cursor.execute(query, (username, password))
user = cursor.fetchone()
if user:
print("yeah!")
return True
else:
print("no!")
return False
except psycopg2.Error as e:
print(f"network err: {e}")
return False
finally:
if conn:
cursor.close()
conn.close()
username = input("логин: ")
password = input("пароль: ")
authenticate_user(username, password)