diff --git a/Password_manager/Password_manager.vcxproj b/Password_manager/Password_manager.vcxproj
index 8107d52..1dc1207 100644
--- a/Password_manager/Password_manager.vcxproj
+++ b/Password_manager/Password_manager.vcxproj
@@ -133,6 +133,8 @@
+
+
diff --git a/Password_manager/Password_manager.vcxproj.filters b/Password_manager/Password_manager.vcxproj.filters
index 35be496..0186117 100644
--- a/Password_manager/Password_manager.vcxproj.filters
+++ b/Password_manager/Password_manager.vcxproj.filters
@@ -24,6 +24,12 @@
Source Files
+
+ Source Files
+
+
+ Source Files
+
diff --git a/Password_manager/include/Buffer.h b/Password_manager/include/Buffer.h
index 75fc65b..59c6cde 100644
--- a/Password_manager/include/Buffer.h
+++ b/Password_manager/include/Buffer.h
@@ -1,49 +1,28 @@
#pragma once
-
+#include
class Buffer
{
public:
- unsigned char* buffer = nullptr;
- int taken = 0;
- int size = 0;
- Buffer(int size)
- {
- this->size = size;
- this->buffer = new unsigned char[size];
- }
+ uint8_t* buffer = nullptr;
+ size_t taken = 0;
+ size_t size = 0;
- Buffer() {
- size = 0;
- buffer = nullptr;
- }
+ Buffer(size_t size);
+ Buffer();
+ ~Buffer();
+ bool resize(size_t new_size);
+ void add(uint8_t* data, size_t data_size);
- ~Buffer()
- {
- if (buffer) delete[] buffer;
- }
+ // Removes data from buffer without checking if it's in the buffer
+ void remove_fast(uint8_t* data, size_t data_size);
- void resize(int new_size)
- {
- unsigned char* new_buffer = (unsigned char*)realloc(buffer, new_size);
- if (!new_buffer)
- {
- printf_s("Error resizing buffer\n");
- return;
- }
+ void remove(size_t index, size_t data_size);
- buffer = new_buffer;
- size = new_size;
- }
+ size_t find(uint8_t* data, size_t data_size);
- void add(void* data, int data_size)
- {
- if (taken + data_size > size)
- {
- resize(size + data_size);
- }
- memcpy_s(buffer + taken, size - taken, data, data_size);
- taken += data_size;
- }
+ void remove(uint8_t* data, size_t data_size);
+
+ void clear() { taken = 0; }
};
\ No newline at end of file
diff --git a/Password_manager/include/func.h b/Password_manager/include/func.h
index 69fda17..3cf863f 100644
--- a/Password_manager/include/func.h
+++ b/Password_manager/include/func.h
@@ -5,87 +5,31 @@
struct Pass
{
- char label[20];
- char password[20];
+ char label[21];
+ char password[21];
- Pass()
- {
- memset(label, 0, 20);
- memset(password, 0, 20);
- };
+ Pass() = default;
};
-bool find_password(Buffer* buff, char* label, char* password)
+enum class Args
{
- Pass* passwords = (Pass*)buff->buffer;
+ Get, // get password for label
+ Generate, // generate password for label
+ List, // list all labels
+ Delete, // delete password for label
+ Print_all_p, // print all passwords
+ Input, // input password for label
+ Error // error
+};
- for (int i = 0; i < buff->taken / sizeof(Pass); i++)
- {
- if (!strcmp(passwords[i].label, label))
- {
- strcpy_s(password, 20, passwords[i].password);
- return true;
- }
- }
- return false;
-}
+Pass* find_password(Buffer* buff, char* label);
-void generate_password(char* password)
-{
- srand(time(NULL));
- char characters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~!@#$%^&*()_-+={[}]|:;<,>.?";
- for (int i = 0; i < 15; i++)
- {
- password[i] = characters[rand() % (sizeof(characters) - 1)];
- }
- password[15] = '\0';
-}
+void generate_password(char* password);
-bool save_buffer_to_file(Buffer* buffer)
-{
- std::ofstream file("passwords.bin", std::ios::binary);
- if (!file.is_open())
- {
- printf_s("Error saving file\n");
- return false;
- }
- file.write((char*)buffer->buffer, buffer->taken);
- file.close();
- return true;
-}
+bool save_buffer_to_file(Buffer* buffer);
-bool load_buffer_from_file(Buffer* buffer)
-{
+bool load_buffer_from_file(Buffer* buffer);
- std::ifstream file("passwords.bin", std::ios::binary);
- if (!file.is_open()) return false;
+void print_usage();
- file.seekg(0, std::ios::end);
- buffer->resize(file.tellg());
- file.seekg(0, std::ios::beg);
- file.read((char*)buffer->buffer, buffer->size);
-
- if (file)
- buffer->taken = buffer->size;
- else
- buffer->taken = file.gcount();
-
- file.close();
- return true;
-}
-
-
-void print_usage()
-{
- printf_s(" Usage:\n\n");
- printf_s(" password_manager.exe [flags]\n\n");
- printf_s(" Flags:\n\n");
- printf_s(" -h\t\t\tprint this message WIP\n");
- printf_s("