-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
108 lines (93 loc) · 2.09 KB
/
main.c
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>
#include <string.h>
#include "application.h"
#include "database.h"
#include "helper.h"
int main(void)
{
sqlite3 *db;
int rc = sqlite3_open("pwdmngr.db", &db);
if (rc)
{
fprintf(stderr, "Error opening database: %s\n", sqlite3_errmsg(db));
return 1;
}
printf("\nCHOOSE OPTIONS BY SPECIFYING A NUMBER\n");
int running = 1;
int *option = NULL;
// Login loop
while (running)
{
printf("\n1. Register \n");
printf("2. Login \n");
printf("3. Exit \n");
if (option != NULL)
{
free(option);
}
option = get_int("\nChoose an option: ");
switch (*option)
{
case 1:
register_user(db);
break;
case 2:
running = login(db);
break;
case 3:
sqlite3_close(db);
free(option);
return 0;
default:
printf("\n\tInvalid option\n");
break;
}
}
running = 1;
// Main loop
while (running)
{
printf("\n1. Generate password \n");
printf("2. Add account\n");
printf("3. Edit account\n");
printf("4. Delete account\n");
printf("5. List all accounts\n");
printf("6. Exit\n");
if (option != NULL)
{
free(option);
}
option = get_int("\nChoose an option: ");
switch (*option)
{
case 1:
free_password();
generate_password();
break;
case 2:
add_account_data(db);
break;
case 3:
edit_account(db);
break;
case 4:
delete_account(db);
break;
case 5:
list_all_accounts(db);
break;
case 6:
running = 0;
break;
default:
printf("\n\tInvalid option\n");
break;
}
}
sqlite3_close(db);
free_password();
free(option);
return 0;
}