diff --git a/Password_manager/Password_manager.vcxproj b/Password_manager/Password_manager.vcxproj
index c2cbe6d..aeb7b6d 100644
--- a/Password_manager/Password_manager.vcxproj
+++ b/Password_manager/Password_manager.vcxproj
@@ -102,7 +102,7 @@
Level3
true
- _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ _DEBUG;_CONSOLE%(PreprocessorDefinitions)
true
$(SolutionDir)dependences\openssl\lib\$(Configuration)\include;$(SolutionDir)Password_manager\include
@@ -133,6 +133,7 @@
+
@@ -141,6 +142,7 @@
+
diff --git a/Password_manager/Password_manager.vcxproj.filters b/Password_manager/Password_manager.vcxproj.filters
index 9ee8c2a..d0fc592 100644
--- a/Password_manager/Password_manager.vcxproj.filters
+++ b/Password_manager/Password_manager.vcxproj.filters
@@ -33,6 +33,9 @@
Source Files
+
+ Source Files
+
@@ -50,5 +53,8 @@
Header Files
+
+ Header Files
+
\ No newline at end of file
diff --git a/Password_manager/include/arg_func.h b/Password_manager/include/arg_func.h
new file mode 100644
index 0000000..6fa089b
--- /dev/null
+++ b/Password_manager/include/arg_func.h
@@ -0,0 +1,22 @@
+#pragma once
+
+struct Pass;
+class Buffer;
+class Cryptography;
+#include
+
+Pass* arg_get(Buffer& decrypted_buffer, const char* label);
+
+Pass* arg_generate(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto);
+
+void arg_list(Buffer& decrypted_buffer);
+
+void arg_delete(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto);
+
+void arg_print_all_p(Buffer& decrypted_buffer, std::string& user_pass);
+
+Pass* arg_input(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto);
+
+void arg_change(Buffer& decrypted_buffer, Buffer& encrypted_buffer, std::string& user_pass, Cryptography& crypto);
+
+void arg_show(Buffer& decrypted_buffer, const char* label);
\ No newline at end of file
diff --git a/Password_manager/include/func.h b/Password_manager/include/func.h
index 07e7c91..064b942 100644
--- a/Password_manager/include/func.h
+++ b/Password_manager/include/func.h
@@ -26,7 +26,7 @@ enum class Arg
Error // error
};
-Pass* find_password(Buffer* buff, char* label);
+Pass* find_password(Buffer* buff, const char* label);
void generate_password(char* password);
diff --git a/Password_manager/source/arg_func.cpp b/Password_manager/source/arg_func.cpp
new file mode 100644
index 0000000..2458832
--- /dev/null
+++ b/Password_manager/source/arg_func.cpp
@@ -0,0 +1,180 @@
+
+#include "arg_func.h"
+#include "func.h"
+#include
+#include "win.h"
+#include "func.h"
+#include "buffer.h"
+#include "cryptography.h"
+
+
+Pass* arg_get(Buffer& decrypted_buffer, const char* label)
+{
+ Pass* pass = find_password(&decrypted_buffer, label);
+ if (!pass) printf_s("Password not found\n");
+ return pass;
+}
+
+Pass* arg_generate(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto)
+{
+ printf_s("Generating password for %s\n", label);
+ Pass* pass = find_password(&decrypted_buffer, label);
+ Pass new_pass = { 0 };
+ if (pass != nullptr) generate_password(pass->password);
+ else
+ {
+ generate_password(new_pass.password);
+ strcpy_s(new_pass.label, MAX_STRING_SIZE, label);
+ int position = decrypted_buffer.add((uint8_t*)&new_pass, sizeof(Pass));
+ if (position < 0)
+ {
+ printf_s("Error adding password\n");
+ return nullptr;
+ }
+ pass = (Pass*)(decrypted_buffer.buffer + position);
+ }
+ crypto.encrypt(&decrypted_buffer, &encrypted_buffer);
+ save_buffer_to_file(&encrypted_buffer);
+ return pass;
+}
+
+void arg_list(Buffer& decrypted_buffer)
+{
+ Pass* passwords = (Pass*)decrypted_buffer.buffer;
+ for (int i = 0; i < decrypted_buffer.taken / sizeof(Pass); i++)
+ {
+ printf_s("%s\n", passwords[i].label);
+ }
+}
+
+void arg_delete(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto)
+{
+ printf_s("Deleting password for %s\n", label);
+ Pass* pass = find_password(&decrypted_buffer, label);
+ if (!pass)
+ {
+ printf_s("Password not found\n");
+ return;
+ }
+ else
+ {
+ decrypted_buffer.remove_fast((uint8_t*)pass, sizeof(Pass));
+ }
+ crypto.encrypt(&decrypted_buffer, &encrypted_buffer);
+ save_buffer_to_file(&encrypted_buffer);
+ printf_s("Password deleted\n");
+}
+
+void arg_print_all_p(Buffer& decrypted_buffer, std::string& user_pass)
+{
+ printf_s("Input main password for confirmation:\n");
+ std::string new_string = get_passwd();
+ if (new_string.empty())
+ {
+ printf_s("Error getting password\n");
+ return;
+ }
+ if (new_string != user_pass)
+ {
+ printf_s("Wrong password\n");
+ return;
+ }
+ Pass* passwords = (Pass*)decrypted_buffer.buffer;
+ for (int i = 0; i < decrypted_buffer.taken / sizeof(Pass); i++)
+ {
+ printf_s("%s: %s\n", passwords[i].label, passwords[i].password);
+ }
+}
+
+Pass* arg_input(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto)
+{
+ printf_s("Input password for %s:\n", label);
+
+ std::string new_string = get_passwd();
+
+
+ if (new_string.empty())
+ {
+ printf_s("Error getting password\n");
+ return nullptr;
+ }
+
+ Pass* pass = find_password(&decrypted_buffer, label);
+ Pass new_pass = { 0 };
+
+
+ if (pass != nullptr)
+ {
+ strcpy_s(pass->password, MAX_STRING_SIZE, new_string.c_str());
+ }
+ else
+ {
+ strcpy_s(new_pass.password, MAX_STRING_SIZE, new_string.c_str());
+ strcpy_s(new_pass.label, MAX_STRING_SIZE, label);
+ int position = decrypted_buffer.add((uint8_t*)&new_pass, sizeof(Pass));
+ if (position < 0)
+ {
+ printf_s("Error adding password\n");
+ return nullptr;
+ }
+ pass = (Pass*)(decrypted_buffer.buffer + position);
+ }
+
+ crypto.encrypt(&decrypted_buffer, &encrypted_buffer);
+ save_buffer_to_file(&encrypted_buffer);
+ return pass;
+}
+
+void arg_change(Buffer& decrypted_buffer, Buffer& encrypted_buffer, std::string& user_pass, Cryptography& crypto)
+{
+ printf_s("Input main password for confirmation:");
+
+ std::string new_string = get_passwd();
+ if (new_string.empty())
+ {
+ printf_s("Error getting password\n");
+ return;
+ }
+
+ if (new_string != user_pass)
+ {
+ printf_s("Passwords don't match\n");
+ return;
+ }
+
+ printf_s("Input new password:");
+ new_string = get_passwd();
+ if (new_string.empty())
+ {
+ printf_s("Error getting password\n");
+ return;
+ }
+
+ printf_s("Input new password again:");
+ user_pass = get_passwd();
+ if (user_pass.empty())
+ {
+ printf_s("Error getting password\n");
+ return;
+ }
+
+ if (new_string != user_pass)
+ {
+ printf_s("Passwords don't match\n");
+ return;
+ }
+
+ 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");
+}
+
+void arg_show(Buffer& decrypted_buffer, const char* label) {
+
+ Pass* pass = find_password(&decrypted_buffer, label);
+ if (!pass)
+ printf_s("Password not found\n");
+ else
+ printf_s("Password: %s\n", pass->password);
+}
\ No newline at end of file
diff --git a/Password_manager/source/func.cpp b/Password_manager/source/func.cpp
index f88d294..7712ff8 100644
--- a/Password_manager/source/func.cpp
+++ b/Password_manager/source/func.cpp
@@ -2,7 +2,7 @@
#include "glob.h"
#include "Buffer.h"
-Pass* find_password(Buffer* buff, char* label)
+Pass* find_password(Buffer* buff, const char* label)
{
Pass* passwords = (Pass*)buff->buffer;
diff --git a/Password_manager/source/main.cpp b/Password_manager/source/main.cpp
index e99615c..4de6f5e 100644
--- a/Password_manager/source/main.cpp
+++ b/Password_manager/source/main.cpp
@@ -4,177 +4,75 @@
#include "buffer.h"
#include "cryptography.h"
#include "func.h"
+#include "arg_func.h"
-Pass* arg_get(Buffer& decrypted_buffer, char* label)
+#ifdef _DEBUG
+
+int main()
{
- Pass* pass = find_password(&decrypted_buffer, label);
- if (!pass) printf_s("Password not found\n");
- return pass;
-}
-
-Pass* arg_generate(Buffer& decrypted_buffer, Buffer& encrypted_buffer, char* label, Cryptography& crypto)
-{
- printf_s("Generating password for %s\n", label);
- Pass* pass = find_password(&decrypted_buffer, label);
- Pass new_pass = { 0 };
- if (pass != nullptr) generate_password(pass->password);
- else
- {
- generate_password(new_pass.password);
- strcpy_s(new_pass.label, MAX_STRING_SIZE, label);
- int position = decrypted_buffer.add((uint8_t*)&new_pass, sizeof(Pass));
- if (position < 0)
- {
- printf_s("Error adding password\n");
- return nullptr;
- }
- pass = (Pass*)decrypted_buffer.buffer + position;
- }
- crypto.encrypt(&decrypted_buffer, &encrypted_buffer);
- save_buffer_to_file(&encrypted_buffer);
- return pass;
-}
-
-void arg_list(Buffer& decrypted_buffer)
-{
- Pass* passwords = (Pass*)decrypted_buffer.buffer;
- for (int i = 0; i < decrypted_buffer.taken / sizeof(Pass); i++)
- {
- printf_s("%s\n", passwords[i].label);
- }
-}
-
-void arg_delete(Buffer& decrypted_buffer, Buffer& encrypted_buffer, char* label, Cryptography& crypto)
-{
- printf_s("Deleting password for %s\n", label);
- Pass* pass = find_password(&decrypted_buffer, label);
- if (!pass)
- {
- printf_s("Password not found\n");
- return;
- }
- else
- {
- decrypted_buffer.remove_fast((uint8_t*)pass, sizeof(Pass));
- }
- crypto.encrypt(&decrypted_buffer, &encrypted_buffer);
- save_buffer_to_file(&encrypted_buffer);
- printf_s("Password deleted\n");
-}
-
-void arg_print_all_p(Buffer& decrypted_buffer, std::string& user_pass)
-{
- printf_s("Input main password for confirmation:\n");
- std::string new_string = get_passwd();
- if (new_string.empty())
- {
- printf_s("Error getting password\n");
- return;
- }
- if (new_string != user_pass)
- {
- printf_s("Wrong password\n");
- return;
- }
- Pass* passwords = (Pass*)decrypted_buffer.buffer;
- for (int i = 0; i < decrypted_buffer.taken / sizeof(Pass); i++)
- {
- printf_s("%s: %s\n", passwords[i].label, passwords[i].password);
- }
-}
-
-Pass* arg_input(Buffer& decrypted_buffer, Buffer& encrypted_buffer, char* label, Cryptography& crypto)
-{
- printf_s("Input password for %s:\n", label);
-
- std::string new_string = get_passwd();
+ Buffer encrypted_buffer;
+ load_buffer_from_file(&encrypted_buffer);
- if (new_string.empty())
- {
- printf_s("Error getting password\n");
- return nullptr;
- }
-
- Pass* pass = find_password(&decrypted_buffer, label);
- Pass new_pass = { 0 };
-
-
- if (pass != nullptr)
- {
- strcpy_s(pass->password, MAX_STRING_SIZE, new_string.c_str());
- }
- else
- {
- strcpy_s(new_pass.password, MAX_STRING_SIZE, new_string.c_str());
- strcpy_s(new_pass.label, MAX_STRING_SIZE, label);
- int position = decrypted_buffer.add((uint8_t*)&new_pass, sizeof(Pass));
- if (position < 0)
- {
- printf_s("Error adding password\n");
- return nullptr;
- }
- pass = (Pass*) decrypted_buffer.buffer + position;
- }
-
- crypto.encrypt(&decrypted_buffer, &encrypted_buffer);
- save_buffer_to_file(&encrypted_buffer);
- return pass;
-}
-
-void arg_change(Buffer& decrypted_buffer, Buffer& encrypted_buffer, std::string& user_pass, Cryptography& crypto)
-{
- printf_s("Input main password for confirmation:");
-
- std::string new_string = get_passwd();
- if (new_string.empty())
- {
- printf_s("Error getting password\n");
- return;
- }
-
- if (new_string != user_pass)
- {
- printf_s("Passwords don't match\n");
- return;
- }
-
- printf_s("Input new password:");
- new_string = get_passwd();
- if (new_string.empty())
- {
- printf_s("Error getting password\n");
- return;
- }
-
- printf_s("Input new password again:");
- user_pass = get_passwd();
+ printf_s("Input main password:");
+ std::string user_pass = get_passwd();
if (user_pass.empty())
{
printf_s("Error getting password\n");
- return;
+ return 1;
}
- if (new_string != user_pass)
- {
- printf_s("Passwords don't match\n");
- return;
- }
+ Cryptography crypto(user_pass.c_str(), user_pass.size());
+
+ Buffer decrypted_buffer;
+ if (encrypted_buffer.size > 0)
+ if (!crypto.decrypt(&encrypted_buffer, &decrypted_buffer)) return 1;
+
+ Pass* pass = nullptr;
+ std::string label = "test";
+
+
+ printf_s("\n--arg_generate--------------------------------------------\n");
+
+ pass = arg_generate(decrypted_buffer, encrypted_buffer, label.c_str(), crypto);
+ printf_s("Generated Password: %s\n", pass->password);
+
+ printf_s("\n--arg_get-------------------------------------------------\n");
+
+ pass = arg_get(decrypted_buffer, label.c_str());
+ printf_s("Password: %s\n", pass->password);
+
+
+ printf_s("\n--arg_list------------------------------------------------\n");
+
+ arg_list(decrypted_buffer);
+
+
+ label = "test2";
+
+ printf_s("\n--arg_input-----------------------------------------------\n");
+
+ pass = arg_input(decrypted_buffer, encrypted_buffer, label.c_str(), crypto);
+ printf_s("Password: %s\n", pass->password);
+
+ printf_s("\n--arg_show------------------------------------------------\n");
+
+ arg_show(decrypted_buffer, label.c_str());
+
+
+ printf_s("\n--arg_print_all_p-----------------------------------------\n");
+
+ arg_print_all_p(decrypted_buffer, user_pass);
+
+ printf_s("\n--arg_delete----------------------------------------------\n");
+
+ arg_delete(decrypted_buffer, encrypted_buffer, label.c_str(), crypto);
+ label = "test";
+ arg_delete(decrypted_buffer, encrypted_buffer, label.c_str(), crypto);
- 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");
}
-void arg_show(Buffer& decrypted_buffer, char* label) {
-
- Pass* pass = find_password(&decrypted_buffer, label);
- if (!pass)
- printf_s("Password not found\n");
- else
- printf_s("Password: %s\n", pass->password);
-}
+#else
int main(int argc, char** argv)
{
@@ -184,7 +82,7 @@ int main(int argc, char** argv)
Buffer encrypted_buffer;
if (!load_buffer_from_file(&encrypted_buffer))
- if (!(args == Arg::Generate)) {
+ if (!(args == Arg::Generate || args == Arg::Input)) {
printf_s("No passwords, try generating password\n");
return 1;
}
@@ -208,61 +106,43 @@ int main(int argc, char** argv)
switch (args)
{
case Arg::Get:
-
pass = arg_get(decrypted_buffer, label);
- if (!pass) return 1;
-
break;
+
case Arg::Generate:
-
pass = arg_generate(decrypted_buffer, encrypted_buffer, label, crypto);
- if (!pass) return 1;
-
break;
+
case Arg::List:
-
arg_list(decrypted_buffer);
- return 0;
-
break;
+
case Arg::Delete:
-
arg_delete(decrypted_buffer, encrypted_buffer, label, crypto);
- return 0;
-
break;
+
case Arg::Print_all_p:
-
arg_print_all_p(decrypted_buffer, user_pass);
- return 0;
-
break;
+
case Arg::Input:
-
- pass = arg_input (decrypted_buffer, encrypted_buffer, label, crypto);
- if (!pass) return 1;
-
+ pass = arg_input(decrypted_buffer, encrypted_buffer, label, crypto);
break;
- case Arg::Change:
+ case Arg::Change:
arg_change(decrypted_buffer, encrypted_buffer, user_pass, crypto);
- return 0;
+
case Arg::Show:
-
arg_show(decrypted_buffer, label);
- return 0;
-
break;
}
- if (pass == nullptr) return 1;
-#ifdef _DEBUG
- printf_s("Password: %s", pass->password);
-#else
+ if (!pass) return 1;
+
printf_s("Password copied to clipboard\n");
put_data_on_clipboard(pass->password);
-#endif
-
}
+
+#endif // _DEBUG
\ No newline at end of file