mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-28 04:46:41 -04:00
Allow generating new passwords for existing entries
This commit is contained in:
@@ -108,16 +108,17 @@ func main() {
|
||||
switch args[3] {
|
||||
case "show", "-s":
|
||||
cli.AddEntry(targetLocation, false, 1)
|
||||
case "update", "-u": // TODO offline.GenUpdate(targetLocation), exit after run
|
||||
case "update", "-u":
|
||||
cli.GenUpdate(targetLocation, true)
|
||||
default:
|
||||
cli.HelpGen()
|
||||
}
|
||||
} else if args[3] == "update" || args[3] == "-u" {
|
||||
switch args[4] {
|
||||
case "show", "-s":
|
||||
cli.AddEntry(targetLocation, false, 1)
|
||||
cli.GenUpdate(targetLocation, false)
|
||||
default:
|
||||
cli.AddEntry(targetLocation, true, 1)
|
||||
cli.GenUpdate(targetLocation, true)
|
||||
}
|
||||
}
|
||||
cli.HelpGen()
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user