Add username to logininfo
This commit is contained in:
parent
3df1a43521
commit
9085e0ebb4
@ -6,12 +6,14 @@ class Buffer;
|
||||
struct LoginInfo
|
||||
{
|
||||
uint32_t label;
|
||||
uint32_t username;
|
||||
uint32_t password;
|
||||
};
|
||||
|
||||
struct LoginInfoPointer
|
||||
{
|
||||
const char* label;
|
||||
const char* username;
|
||||
const char* password;
|
||||
};
|
||||
|
||||
@ -25,7 +27,7 @@ int find_logininfo_in_buffer(Buffer& buffer, const char* label);
|
||||
|
||||
void delete_logininfo_from_buffer(Buffer& buffer, int index_of_pass);
|
||||
|
||||
void add_logininfo_to_buffer(Buffer& buffer, const char* label, const char* password);
|
||||
void add_logininfo_to_buffer(Buffer& buffer, const char* label, const char* username, const char* password);
|
||||
|
||||
LoginInfoPointer get_logininfo_pointer_from_buffer(Buffer& buffer, int index_of_pass);
|
||||
|
||||
|
@ -68,14 +68,25 @@ std::optional<LoginInfoPointer> arg_get(Buffer& decrypted_buffer, const char* la
|
||||
return get_logininfo_pointer_from_buffer(decrypted_buffer, pass);
|
||||
}
|
||||
|
||||
std::string get_user_string() {
|
||||
|
||||
printf_s("Input username:");
|
||||
std::string ret;
|
||||
std::getline(std::cin, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::optional<LoginInfoPointer> arg_generate(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto)
|
||||
{
|
||||
std::string username = get_user_string();
|
||||
|
||||
int default_length = 15;
|
||||
printf_s("Input password length [%d]:", default_length);
|
||||
std::string input;
|
||||
int length = default_length;
|
||||
|
||||
std::getline(std::cin, input);
|
||||
|
||||
|
||||
if (!input.empty())
|
||||
{
|
||||
@ -91,7 +102,7 @@ std::optional<LoginInfoPointer> arg_generate(Buffer& decrypted_buffer, Buffer& e
|
||||
int pass = find_logininfo_in_buffer(decrypted_buffer, label);
|
||||
if (pass >= 0) delete_logininfo_from_buffer(decrypted_buffer, pass);
|
||||
|
||||
add_logininfo_to_buffer(decrypted_buffer, label, password.c_str());
|
||||
add_logininfo_to_buffer(decrypted_buffer, label, username.c_str(), password.c_str());
|
||||
crypto.encrypt(&decrypted_buffer, &encrypted_buffer);
|
||||
encrypted_buffer.save_to_file();
|
||||
Index* index = (Index*)decrypted_buffer.buffer;
|
||||
@ -100,6 +111,8 @@ std::optional<LoginInfoPointer> arg_generate(Buffer& decrypted_buffer, Buffer& e
|
||||
|
||||
std::optional<LoginInfoPointer> arg_input(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto)
|
||||
{
|
||||
std::string username = get_user_string();
|
||||
|
||||
printf_s("Input password for %s:", label);
|
||||
|
||||
std::string new_string = get_user_password();
|
||||
@ -112,7 +125,7 @@ std::optional<LoginInfoPointer> arg_input(Buffer& decrypted_buffer, Buffer& encr
|
||||
int pass = find_logininfo_in_buffer(decrypted_buffer, label);
|
||||
if (pass >= 0) delete_logininfo_from_buffer(decrypted_buffer, pass);
|
||||
|
||||
add_logininfo_to_buffer(decrypted_buffer, label, new_string.c_str());
|
||||
add_logininfo_to_buffer(decrypted_buffer, label, username.c_str(), new_string.c_str());
|
||||
crypto.encrypt(&decrypted_buffer, &encrypted_buffer);
|
||||
encrypted_buffer.save_to_file();
|
||||
Index* index = (Index*)decrypted_buffer.buffer;
|
||||
@ -167,7 +180,8 @@ void arg_print_all_p(Buffer& decrypted_buffer, std::string& user_pass)
|
||||
|
||||
for (size_t i = 0; i < index->count; i++)
|
||||
{
|
||||
printf_s("label: %s\t\t\t", decrypted_buffer.buffer + pass[i].label + index->offset);
|
||||
printf_s("label: %s\t\t", decrypted_buffer.buffer + pass[i].label + index->offset);
|
||||
printf_s("username: %s\t\t", decrypted_buffer.buffer + pass[i].username + index->offset);
|
||||
printf_s("password: %s\n", decrypted_buffer.buffer + pass[i].password + index->offset);
|
||||
}
|
||||
}
|
||||
@ -224,5 +238,9 @@ void arg_show(Buffer& decrypted_buffer, const char* label) {
|
||||
if (pass < 0)
|
||||
printf_s("Password not found\n");
|
||||
else
|
||||
printf_s("Password: %s\n", get_logininfo_pointer_from_buffer(decrypted_buffer, pass).password);
|
||||
{
|
||||
LoginInfoPointer lip = get_logininfo_pointer_from_buffer(decrypted_buffer, pass);
|
||||
printf_s("Username: %s\n", lip.username);
|
||||
printf_s("Password: %s\n", lip.password);
|
||||
}
|
||||
}
|
@ -23,8 +23,9 @@ void delete_logininfo_from_buffer(Buffer& buffer, int index_of_pass)
|
||||
LoginInfo* in_pass = (LoginInfo*)(buffer.buffer + sizeof(Index));
|
||||
|
||||
int size_of_label = strlen((char*)buffer.buffer + in_pass[index_of_pass].label + in_index->offset) + 1;
|
||||
int size_of_username = strlen((char*)buffer.buffer + in_pass[index_of_pass].username + in_index->offset) + 1;
|
||||
int size_of_password = strlen((char*)buffer.buffer + in_pass[index_of_pass].password + in_index->offset) + 1;
|
||||
int size_pass = size_of_label + size_of_password;
|
||||
int size_pass = size_of_label + size_of_username + size_of_password;
|
||||
|
||||
uint8_t* start_of_pass = buffer.buffer + in_pass[index_of_pass].label + in_index->offset;
|
||||
buffer.remove_fast(start_of_pass, size_pass);
|
||||
@ -40,16 +41,18 @@ void delete_logininfo_from_buffer(Buffer& buffer, int index_of_pass)
|
||||
in_index->offset -= sizeof(LoginInfo);
|
||||
}
|
||||
|
||||
void add_logininfo_to_buffer(Buffer& buffer, const char* label, const char* password)
|
||||
void add_logininfo_to_buffer(Buffer& buffer, const char* label, const char* username, const char* password)
|
||||
{
|
||||
int label_start = buffer.add_end((uint8_t*)label, strlen(label) + 1);
|
||||
int username_start = buffer.add_end((uint8_t*)username, strlen(username) + 1);
|
||||
int password_start = buffer.add_end((uint8_t*)password, strlen(password) + 1);
|
||||
|
||||
Index* index = (Index*)buffer.buffer;
|
||||
|
||||
label_start = label_start - index->offset;
|
||||
username_start = username_start - index->offset;
|
||||
password_start = password_start - index->offset;
|
||||
LoginInfo pass = { label_start, password_start };
|
||||
LoginInfo pass = { label_start, username_start, password_start };
|
||||
index->count++;
|
||||
index->offset += sizeof(LoginInfo);
|
||||
|
||||
@ -63,6 +66,7 @@ LoginInfoPointer get_logininfo_pointer_from_buffer(Buffer& buffer, int index_of_
|
||||
LoginInfo* pass = (LoginInfo*)(buffer.buffer + sizeof(Index));
|
||||
LoginInfoPointer ret;
|
||||
ret.label = (const char*)buffer.buffer + pass[index_of_pass].label + index->offset;
|
||||
ret.username = (const char*)buffer.buffer + pass[index_of_pass].username + index->offset;
|
||||
ret.password = (const char*)buffer.buffer + pass[index_of_pass].password + index->offset;
|
||||
return ret;
|
||||
}
|
||||
|
@ -71,9 +71,8 @@ int main()
|
||||
|
||||
if (!login_info.has_value()) return 0;
|
||||
|
||||
printf_s("Password copied to clipboard\n");
|
||||
put_data_on_clipboard(login_info.value().password);
|
||||
|
||||
printf_s("Username: %s\n", login_info.value().username);
|
||||
printf_s("Password: %s\n", login_info.value().password);
|
||||
}
|
||||
|
||||
#else
|
||||
@ -150,8 +149,9 @@ int main(int argc, char** argv)
|
||||
|
||||
if (!login_info.has_value()) return 1;
|
||||
|
||||
printf_s("Password copied to clipboard\n");
|
||||
printf_s("Username: %s\n", login_info.value().username);
|
||||
put_data_on_clipboard(login_info.value().password);
|
||||
printf_s("Password copied to clipboard\n");
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user