-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase_manager.py
52 lines (48 loc) · 1.87 KB
/
database_manager.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import psycopg2
def store_passwords(password, user_email, username, url, app_name):
try:
connection = connect()
cursor = connection.cursor()
postgres_insert_query = """ INSERT INTO accounts (password, email, username, url, app_name) VALUES (%s, %s, %s, %s, %s)"""
record_to_insert = (password, user_email, username, url, app_name)
cursor.execute(postgres_insert_query, record_to_insert)
connection.commit()
except (Exception, psycopg2.Error) as error:
print(error)
def connect():
try:
connection = psycopg2.connect(user='kalle', password='kalle', host='127.0.0.1', database='password_manager')
return connection
except (Exception, psycopg2.Error) as error:
print(error)
def find_password(app_name):
try:
connection = connect()
cursor = connection.cursor()
postgres_select_query = """ SELECT password FROM accounts WHERE app_name = '""" + app_name + "'"
cursor.execute(postgres_select_query, app_name)
connection.commit()
result = cursor.fetchone()
print('Password is: ' )
print(result[0])
except (Exception, psycopg2.Error) as error:
print(error)
def find_users(user_email):
data = ('Password: ', 'Email: ', 'Username: ', 'url: ', 'App/Site name: ')
try:
connection = connect()
cursor = connection.cursor()
postgres_select_query = """ SELECT * FROM accounts WHERE email = '""" + user_email + "'"
cursor.execute(postgres_select_query, user_email)
connection.commit()
result = cursor.fetchall()
print('')
print('RESULT')
print('')
for row in result:
for i in range(0, len(row)-1):
print(data[i] + row[i])
print('')
print('-'*30)
except (Exception, psycopg2.Error) as error:
print(error)