diff --git a/.gitignore b/.gitignore
index 043f362..2636851 100644
--- a/.gitignore
+++ b/.gitignore
@@ -358,4 +358,6 @@ MigrationBackup/
.ionide/
# Fody - auto-generated XML schema
-FodyWeavers.xsd
\ No newline at end of file
+FodyWeavers.xsd
+
+*.bin
\ No newline at end of file
diff --git a/Password_manager/Password_manager.vcxproj b/Password_manager/Password_manager.vcxproj
index b32ade4..db9a7df 100644
--- a/Password_manager/Password_manager.vcxproj
+++ b/Password_manager/Password_manager.vcxproj
@@ -133,8 +133,12 @@
+
+
+
+
diff --git a/Password_manager/Password_manager.vcxproj.filters b/Password_manager/Password_manager.vcxproj.filters
index 8a12c0b..93d5eb2 100644
--- a/Password_manager/Password_manager.vcxproj.filters
+++ b/Password_manager/Password_manager.vcxproj.filters
@@ -18,5 +18,13 @@
Source Files
+
+ Source Files
+
+
+
+
+ Header Files
+
\ No newline at end of file
diff --git a/Password_manager/include/clipboard.hpp b/Password_manager/include/clipboard.hpp
new file mode 100644
index 0000000..f830774
--- /dev/null
+++ b/Password_manager/include/clipboard.hpp
@@ -0,0 +1,3 @@
+#pragma once
+
+bool put_data_on_clipboard(const char* text);
\ No newline at end of file
diff --git a/Password_manager/source/clipboard.cpp b/Password_manager/source/clipboard.cpp
new file mode 100644
index 0000000..f110c98
--- /dev/null
+++ b/Password_manager/source/clipboard.cpp
@@ -0,0 +1,38 @@
+#include
+#include
+#include "clipboard.hpp"
+
+bool put_data_on_clipboard(const char* text) {
+ int len = strlen(text);
+ if (strnlen_s(text, 20) == 0) {
+ std::cerr << "Text is empty" << std::endl;
+ return false;
+ }
+ // Open the clipboard
+ if (!OpenClipboard(nullptr)) {
+ std::cerr << "Failed to open clipboard" << std::endl;
+ return false;
+ }
+ // Allocate global memory for the text
+ HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, strlen(text) + 1);
+ if (!hMem) {
+ CloseClipboard();
+ std::cerr << "Failed to allocate memory for text" << std::endl;
+ return false;
+ }
+ // Copy the text to the allocated memory
+ char* memData = static_cast(GlobalLock(hMem));
+ if (!memData) {
+ CloseClipboard();
+ std::cerr << "Failed to lock memory for text" << std::endl;
+ return false;
+ }
+ strcpy_s(memData, strlen(text) + 1, text);
+ GlobalUnlock(hMem);
+ // Set the data to the clipboard
+ EmptyClipboard();
+ SetClipboardData(CF_TEXT, hMem);
+ // Clean up and close the clipboard
+ CloseClipboard();
+ return true;
+}
\ No newline at end of file
diff --git a/Password_manager/source/main.cpp b/Password_manager/source/main.cpp
index 9071219..f51b44d 100644
--- a/Password_manager/source/main.cpp
+++ b/Password_manager/source/main.cpp
@@ -1,7 +1,100 @@
#include
+#include
+
+#include "clipboard.hpp"
+
+struct Pass
+{
+ char label[20];
+ char password[20];
+
+ Pass()
+ {
+ memset(label, 0, 20);
+ memset(password, 0, 20);
+ };
+};
+
+void load_password(char* label, char* password)
+{
+ std::ifstream file("passwords.bin", std::ios::binary);
+ if (!file.is_open())
+ {
+ std::cout << "Error opening file\n";
+ return;
+ }
+ Pass pass;
+ while (file.read((char*)&pass, sizeof(Pass)))
+ {
+ if (strcmp(pass.label, label) == 0)
+ {
+ strcpy_s(password, 20, pass.password);
+ return;
+ }
+ }
+ std::cout << "Password not found\n";
+ file.close();
+}
+
+void save_password(char* label, char* password)
+{
+ std::ofstream file("passwords.bin", std::ios::binary | std::ios::app);
+ if (!file.is_open())
+ {
+ std::cout << "Error opening file\n";
+ return;
+ }
+ Pass pass;
+ strcpy_s(pass.label, 20, label);
+ strcpy_s(pass.password, 20, password);
+ file.write((char*)&pass, sizeof(Pass));
+ file.close();
+}
+
+void generate_password(char* password)
+{
+ char characters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~!@#$%^&*()_-+={[}]|:;<,>.?";
+ for (int i = 0; i < 15; i++)
+ {
+ password[i] = characters[rand() % (sizeof(characters) - 1)];
+ }
+ password[15] = '\0';
+}
int main(int argc, char** argv)
{
- std::cout << "Hello, World!\n";
+ bool generate = false;
+ if (argc < 2)
+ {
+ std::cout << "Usage: \n";
+ std::cout << "Password_manager.exe \n";
+ return 1;
+ }
+
+ if (!strcmp("-g", argv[1]))
+ {
+ if (argc < 3)
+ {
+ std::cout << "Usage: \n";
+ std::cout << "Password_manager.exe -g \n";
+ return 1;
+ }
+ std::cout << "Generating password for " << argv[2] << "\n";
+ generate = true;
+ }
+
+ char password[20] = { 0 };
+
+ if (generate)
+ {
+ generate_password(password);
+ save_password(argv[2], password);
+ put_data_on_clipboard(password);
+ }
+ else
+ {
+ load_password(argv[1], password);
+ put_data_on_clipboard(password);
+ }
}