-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordSafe.cpp
More file actions
77 lines (70 loc) · 2.34 KB
/
Copy pathPasswordSafe.cpp
File metadata and controls
77 lines (70 loc) · 2.34 KB
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
/*********************************************************************
* Password Safe
*
* Zaq Nelson
*
* A simple Password Safe for my own purposes.
*
* This handles all of the communication between the GUI
* and the C++ implementations
*
**********************************************************************/
#include "myEncryption.h" // For encryption
#include "myRNG.h" // For PRNG numbers
#include "myAuthentication.h" // For Authentication
#include <string> // For Strings
#include <iostream> // For Debugging
#define FILENAME "logins.txt" // Logins stored here
/**************************************************************
* MAIN
* The GUI will send requests based on the arguments provided
* a code will always be a part of it to know the request
***************************************************************/
int main(int argc, char **argv)
{
/*
Code 0: Decrypt login information, comes with a string for auth
Also just logs in to the platform
Code 1: Update master password, comes with 2 strings
Code 2: Encrypt the file, comes with key
Code 3: Generate a random salt for a login (for extensibility)
Code 4:
return 0 If access was denied
return 1 If access was approved
*/
std::string masterPassword = argv[2];
std::string newPassword; // Only assigned if exists
if (argc == 4)
newPassword = argv[3];
int code; // Var for switch
sscanf (argv[1],"%d",&code); // cast to int for switch
// Debugging
std::cout << code;
switch (code)
{
case 0:
if(authenticate(masterPassword)) // Authenticate Master Password
{
decrypt(masterPassword, FILENAME);
return 1;
}
else
return 0;
break;
case 1:
if(updatePassword(newPassword, masterPassword)) // Update the password
{
return 1;
}
else
return 0;
break;
case 2:
encrypt(masterPassword, FILENAME); // Called at termination of GUI
break;
case 3: // Generate a random salt!
return RNG(100, 1000);
default:
break;
}
}