Add README.md and Flags: -s -c
This commit is contained in:
parent
6d9404b9b5
commit
05cb50acb4
@ -13,12 +13,11 @@ public:
|
||||
~Cryptography();
|
||||
bool encrypt(Buffer* plain, Buffer* encrypted);
|
||||
bool decrypt(Buffer* encrypted, Buffer* decrypted);
|
||||
bool generate_key_and_iv_from_password(const char* password, size_t size);
|
||||
|
||||
private:
|
||||
uint8_t key[32] = { 0 };
|
||||
uint8_t iv[16] = { 0 };
|
||||
EVP_CIPHER_CTX* ctx = nullptr;
|
||||
|
||||
bool generate_key_and_iv_from_password(const char* password, size_t size);
|
||||
bool handleErrors();
|
||||
};
|
||||
|
@ -20,6 +20,8 @@ enum class Args
|
||||
Delete, // delete password for label
|
||||
Print_all_p, // print all passwords
|
||||
Input, // input password for label
|
||||
Change, // change main password
|
||||
Show, // show password for label
|
||||
Error // error
|
||||
};
|
||||
|
||||
|
@ -21,6 +21,7 @@ Buffer::~Buffer()
|
||||
|
||||
bool Buffer::resize(size_t new_size)
|
||||
{
|
||||
if(size >= new_size) return true;
|
||||
uint8_t* new_buffer = (uint8_t*)realloc(buffer, new_size);
|
||||
if (!new_buffer)
|
||||
{
|
||||
|
@ -70,8 +70,10 @@ void print_usage()
|
||||
printf_s(" -g <label> \t generate or update password of this label\n");
|
||||
printf_s(" -d <label> \t delete password of this label\n");
|
||||
printf_s(" -i <label> \t input password for this label max %d char\n", MAX_STRING_SIZE);
|
||||
printf_s(" -s <label> \t show password for this label\n");
|
||||
printf_s(" -l \t list all labels\n");
|
||||
printf_s(" -p \t print all passwords\n");
|
||||
printf_s(" -c \t change master password\n");
|
||||
}
|
||||
|
||||
Args get_args(int argc, char** argv, char** label) {
|
||||
@ -89,6 +91,7 @@ Args get_args(int argc, char** argv, char** label) {
|
||||
|
||||
if (!strcmp("-l", argv[1])) return Args::List;
|
||||
if (!strcmp("-p", argv[1])) return Args::Print_all_p;
|
||||
if (!strcmp("-c", argv[1])) return Args::Change;
|
||||
|
||||
if (argc < 3)
|
||||
{
|
||||
@ -98,22 +101,10 @@ Args get_args(int argc, char** argv, char** label) {
|
||||
|
||||
*label = argv[2];
|
||||
|
||||
if (!strcmp("-g", argv[1]))
|
||||
{
|
||||
printf_s("Generating password for %s\n", argv[2]);
|
||||
return Args::Generate;
|
||||
}
|
||||
|
||||
if (!strcmp("-d", argv[1]))
|
||||
{
|
||||
printf_s("Deleting password for %s\n", argv[2]);
|
||||
return Args::Delete;
|
||||
}
|
||||
|
||||
if (!strcmp("-i", argv[1]))
|
||||
{
|
||||
return Args::Input;
|
||||
}
|
||||
if (!strcmp("-g", argv[1])) return Args::Generate;
|
||||
if (!strcmp("-d", argv[1])) return Args::Delete;
|
||||
if (!strcmp("-i", argv[1])) return Args::Input;
|
||||
if (!strcmp("-s", argv[1])) return Args::Show;
|
||||
|
||||
return Args::Error;
|
||||
}
|
@ -49,7 +49,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
break;
|
||||
case Args::Generate:
|
||||
|
||||
printf_s("Generating password for %s\n", label);
|
||||
pass = find_password(&decrypted_buffer, label);
|
||||
|
||||
if (pass != nullptr) generate_password(pass->password);
|
||||
@ -76,6 +76,7 @@ int main(int argc, char** argv)
|
||||
|
||||
break;
|
||||
case Args::Delete:
|
||||
printf_s("Deleting password for %s\n", label);
|
||||
pass = find_password(&decrypted_buffer, label);
|
||||
|
||||
if (!pass)
|
||||
@ -98,7 +99,7 @@ int main(int argc, char** argv)
|
||||
break;
|
||||
case Args::Print_all_p:
|
||||
|
||||
printf_s("input main password for confirmation:\n");
|
||||
printf_s("Input main password for confirmation:\n");
|
||||
new_string = get_passwd();
|
||||
if (new_string.empty())
|
||||
{
|
||||
@ -147,6 +148,66 @@ int main(int argc, char** argv)
|
||||
crypto.encrypt(&decrypted_buffer, &encrypted_buffer);
|
||||
save_buffer_to_file(&encrypted_buffer);
|
||||
break;
|
||||
|
||||
case Args::Change:
|
||||
|
||||
printf_s("Input main password for confirmation:");
|
||||
new_string = get_passwd();
|
||||
if (new_string.empty())
|
||||
{
|
||||
printf_s("Error getting password\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (new_string != user_pass)
|
||||
{
|
||||
printf_s("Passwords don't match\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf_s("Input new password:");
|
||||
new_string = get_passwd();
|
||||
if (new_string.empty())
|
||||
{
|
||||
printf_s("Error getting password\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf_s("Input new password again:");
|
||||
user_pass = get_passwd();
|
||||
if (user_pass.empty())
|
||||
{
|
||||
printf_s("Error getting password\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (new_string != user_pass)
|
||||
{
|
||||
printf_s("Passwords don't match\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
crypto.generate_key_and_iv_from_password(new_string.c_str(), new_string.size());
|
||||
crypto.encrypt(&decrypted_buffer, &encrypted_buffer);
|
||||
save_buffer_to_file(&encrypted_buffer);
|
||||
|
||||
printf_s("Password changed\n");
|
||||
|
||||
return 0;
|
||||
|
||||
case Args::Show:
|
||||
|
||||
pass = find_password(&decrypted_buffer, label);
|
||||
if (!pass)
|
||||
{
|
||||
printf_s("Password not found\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf_s("Password: %s\n", pass->password);
|
||||
return 0;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (pass == nullptr) return 1;
|
||||
|
6
README.md
Normal file
6
README.md
Normal file
@ -0,0 +1,6 @@
|
||||
# Download executable:
|
||||
http://download.petrovv.com/homep/password_manager.zip
|
||||
|
||||
|
||||
# Usage:
|
||||
The main password that you in input at first password generation is the main password for the program. It is used to encrypt all other passwords. If you forget it, you will not be able to decrypt your passwords. So be careful with it. You can change it later.
|
Loading…
x
Reference in New Issue
Block a user