2023-08-13 21:15:30 +02:00

74 lines
1.4 KiB
C++

#include <iostream>
#include <fstream>
#include "win.h"
#include "buffer.h"
#include "cryptography.h"
#include "func.h"
int main(int argc, char** argv)
{
bool generate = false;
if (argc < 2)
{
print_usage();
return 1;
}
if (!strcmp("-g", argv[1]))
{
if (argc < 3)
{
print_usage();
return 1;
}
printf_s("Generating password for %s\n", argv[2]);
generate = true;
}
Buffer encrypted_buffer;
if (!load_buffer_from_file(&encrypted_buffer))
if (!generate) {
printf_s("No passwords, try generating password\n");
return 1;
}
printf_s("Input main password:");
std::string user_pass = get_passwd();
if (user_pass.empty())
{
printf_s("Error getting password\n");
return 1;
}
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;
if (generate)
{
generate_password(pass.password);
strcpy_s(pass.label, 20, argv[2]);
decrypted_buffer.add(&pass, sizeof(Pass));
crypto.encrypt(&decrypted_buffer, &encrypted_buffer);
save_buffer_to_file(&encrypted_buffer);
}
else
{
if (!find_password(&decrypted_buffer, argv[1], pass.password))
{
printf_s("Password not found\n");
return 1;
}
}
printf_s("Password: %s\n", pass.password);
printf_s("Password copied to clipboard\n");
put_data_on_clipboard(pass.password);
}