Add update label name
This commit is contained in:
parent
5767e9757c
commit
a76b2f5885
@ -18,6 +18,7 @@ enum class Arg
|
||||
Show, // show password for label
|
||||
Error, // error
|
||||
Username, // update username
|
||||
Name, // update label name
|
||||
};
|
||||
|
||||
Arg get_args(int argc, char** argv, char** label);
|
||||
@ -30,6 +31,8 @@ std::optional<LoginInfoPointer> arg_input(Buffer& decrypted_buffer, Buffer& encr
|
||||
|
||||
void arg_username(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto);
|
||||
|
||||
void arg_label_name(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);
|
||||
|
@ -21,6 +21,7 @@ void print_args()
|
||||
printf_s(" -d <label> \t delete password of this label\n");
|
||||
printf_s(" -s <label> \t show password for this label\n");
|
||||
printf_s(" -u <label> \t update username for this label\n");
|
||||
printf_s(" -n <label> \t update label name\n");
|
||||
printf_s(" -l \t list all labels\n");
|
||||
printf_s(" -p \t print all passwords\n");
|
||||
printf_s(" -c \t change master password\n");
|
||||
@ -56,6 +57,7 @@ Arg get_args(int argc, char** argv, char** label) {
|
||||
if (!strcmp("-i", argv[1])) return Arg::Input;
|
||||
if (!strcmp("-s", argv[1])) return Arg::Show;
|
||||
if (!strcmp("-u", argv[1])) return Arg::Username;
|
||||
if (!strcmp("-n", argv[1])) return Arg::Name;
|
||||
|
||||
return Arg::Error;
|
||||
}
|
||||
@ -153,6 +155,30 @@ void arg_username(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char
|
||||
encrypted_buffer.save_to_file();
|
||||
}
|
||||
|
||||
void arg_label_name(Buffer& decrypted_buffer, Buffer& encrypted_buffer, const char* label, Cryptography& crypto)
|
||||
{
|
||||
int pass = find_logininfo_in_buffer(decrypted_buffer, label);
|
||||
|
||||
if (pass < 0)
|
||||
{
|
||||
printf_s("LoginInfo not found\n");
|
||||
return;
|
||||
}
|
||||
|
||||
LoginInfoPointer lip = get_logininfo_pointer_from_buffer(decrypted_buffer, pass);
|
||||
std::string password = lip.password;
|
||||
std::string username = lip.username;
|
||||
|
||||
printf_s("Input new label name for %s:", lip.label);
|
||||
std::string name;
|
||||
std::getline(std::cin, name);
|
||||
|
||||
delete_logininfo_from_buffer(decrypted_buffer, pass);
|
||||
add_logininfo_to_buffer(decrypted_buffer, name.c_str(), username.c_str(), password.c_str());
|
||||
crypto.encrypt(&decrypted_buffer, &encrypted_buffer);
|
||||
encrypted_buffer.save_to_file();
|
||||
}
|
||||
|
||||
void arg_list(Buffer& decrypted_buffer)
|
||||
{
|
||||
Index* index = (Index*)decrypted_buffer.buffer;
|
||||
|
@ -64,6 +64,10 @@ int main()
|
||||
arg_username(decrypted_buffer, encrypted_buffer, label, crypto);
|
||||
break;
|
||||
|
||||
case Arg::Name:
|
||||
arg_label_name(decrypted_buffer, encrypted_buffer, label, crypto);
|
||||
break;
|
||||
|
||||
case Arg::Change:
|
||||
arg_change(decrypted_buffer, encrypted_buffer, user_pass, crypto);
|
||||
break;
|
||||
@ -146,6 +150,10 @@ int main(int argc, char** argv)
|
||||
arg_username(decrypted_buffer, encrypted_buffer, label, crypto);
|
||||
break;
|
||||
|
||||
case Arg::Name:
|
||||
arg_label_name(decrypted_buffer, encrypted_buffer, label, crypto);
|
||||
break;
|
||||
|
||||
case Arg::Change:
|
||||
arg_change(decrypted_buffer, encrypted_buffer, user_pass, crypto);
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user