From c0d141a02e00d74614f4a572bc87d3a7c87a2141 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Thu, 7 Mar 2024 19:09:23 -0500 Subject: [PATCH] Allow generating new passwords for existing entries --- src/cli/edit.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/cli/edit.go b/src/cli/edit.go index f4bc5b1..7745d34 100644 --- a/src/cli/edit.go +++ b/src/cli/edit.go @@ -51,3 +51,25 @@ func EditEntry(targetLocation string, hidePassword bool, field int) { os.Exit(1) } } + +// GenUpdate generates a new password for an entry at targetLocation (user input) +func GenUpdate(targetLocation string, hidePassword bool) { + // ensure targetLocation exists + offline.TargetIsFile(targetLocation, true, 2) + + // read old entry data + unencryptedEntry := offline.DecryptGPG(targetLocation) + + // generate a new password + unencryptedEntry[0] = offline.StringGen(inputInt("Password length:"), inputBinary("Generate a complex (special characters) password?"), 0.2) + + // write and preview the modified entry + if offline.EntryIsNotEmpty(unencryptedEntry) { + offline.WriteEntry(targetLocation, unencryptedEntry) + fmt.Println(ansiBold + "\nEntry Preview:" + offline.AnsiReset) + EntryReader(unencryptedEntry, hidePassword) + } else { + fmt.Println(offline.AnsiError + "No data supplied for entry" + offline.AnsiReset) + os.Exit(1) + } +}