-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPasswordManager.c
142 lines (113 loc) · 3.84 KB
/
PasswordManager.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
void accessReccords(char path[256]);
void enterReccord(char path[256]);
void encryptReccord(char reccorc[256]);
void decryptReccord(char reccorc[256]);
bool checkEntry(char buffer[256]);
int main(){
bool condition = true;
system("clear");
system("swift /Users/rgoel/Downloads/pass-mgr/Authenticate.swift");
printf("\n----------------------------------------------------------------");
printf("\n| |");
printf("\n|\t\tWelcome to Password Manager\t\t |\n");
printf("| |");
char path[] = "/Users/rgoel/desktop/passwords.txt";
while(condition){
char answer[50];
printf("\n----------------------------------------------------------------\n");
printf("|\t\t Choose an Option Below\t\t |");
printf("\n----------------------------------------------------------------\n");
printf("| Access your stored passwords (a)");
printf("\n| Enter new password (e)");
printf("\n| Quit program (q)");
printf("\n\n>>> ");
scanf("%s", answer);
// printf("\n\n%s", answer);
if(strcmp(answer, "a") == 0){
accessReccords(path);
} else if(strcmp(answer, "e") == 0){
enterReccord(path);
} else if (strcmp(answer, "q") == 0){
system("clear");
condition = false;
}
}
return 0;
}
void accessReccords(char path[256]){
FILE *fptr;
fptr = fopen(path,"r");
if (fptr == NULL){
printf("\n**Could not access passwords**\n");
} else {
printf("\n*********************** Stored Reccords ***********************\n");
const unsigned MAX_LENGTH = 256;
char buffer[MAX_LENGTH];
while (fgets(buffer, MAX_LENGTH, fptr)){
decryptReccord(buffer);
printf("\n");
printf("--> %s", buffer);
}
}
printf("\n");
fclose(fptr);
}
void enterReccord(char path[256]){
FILE *fptr;
fptr = fopen(path,"a");
if (fptr == NULL){
printf("\n**Could not access passwords**\n");
} else {
char reccordName[50];
char userName[50];
char password[50];
char buffer[256];
char confirm[50];
printf("\nEnter the name of this reccord >>> ");
scanf("%s", reccordName);
printf("Username >>> ");
scanf("%s", userName);
printf("Password >>> ");
scanf("%s", password);
sprintf(buffer, "%s: username=\"%s\" | password=\"%s\"", reccordName, userName, password);
while(checkEntry(buffer) == false){
printf("\nEnter the name of this reccord >>> ");
scanf("%s", reccordName);
printf("Username >>> ");
scanf("%s", userName);
printf("Password >>> ");
scanf("%s", password);
sprintf(buffer, "%s: username=\"%s\" | password=\"%s\"", reccordName, userName, password);
}
encryptReccord(buffer);
fprintf(fptr, "\n");
fprintf(fptr, buffer);
decryptReccord(buffer);
printf("\nEntered reccord %s ", buffer);
}
printf("\n");
fclose(fptr);
}
void encryptReccord(char reccord[256]){
for(int i = 0; i < strlen(reccord); i++){
reccord[i] = reccord[i]+100;
}
}
void decryptReccord(char reccord[256]){
for(int i = 0; i < strlen(reccord); i++){
reccord[i] = reccord[i]-100;
}
}
bool checkEntry(char buffer[256]){
char confirm[50];
printf("Correct (enter)/Incorrect (q)? %s\n>>> ", buffer);
scanf("%s", confirm);
if(strcmp(confirm, "q") == 0){
return false;
}
return true;
}