Implement password hiding in entry readouts

This commit is contained in:
2024-03-01 22:11:59 -05:00
parent 51313eb307
commit b17a3ae372
2 changed files with 13 additions and 8 deletions
+3 -3
View File
@@ -26,12 +26,13 @@ func main() {
// entry reader shortcut (if no other arguments are supplied) // entry reader shortcut (if no other arguments are supplied)
if argsCount == 1 { if argsCount == 1 {
cli.EntryReaderShortcut(targetLocation) cli.EntryReaderShortcut(targetLocation, true)
// perform other operations on the entry (if other arguments are supplied) // perform other operations on the entry (if other arguments are supplied)
} else if argsCount == 2 { } else if argsCount == 2 {
switch args[1] { switch args[1] {
case "show", "-s":
cli.EntryReaderShortcut(targetLocation, false)
case "shear": // TODO offline.Shear(targetLocation), exit after run case "shear": // TODO offline.Shear(targetLocation), exit after run
case "gen": // TODO offline.Gen(targetLocation), exit after run case "gen": // TODO offline.Gen(targetLocation), exit after run
case "copy": case "copy":
@@ -42,7 +43,6 @@ func main() {
cli.HelpAdd() cli.HelpAdd()
default: default:
cli.HelpMain() cli.HelpMain()
} }
} else if argsCount == 3 { } else if argsCount == 3 {
+10 -5
View File
@@ -6,9 +6,10 @@ import (
"os" "os"
) )
const ansiShownPassword = "\033[38;5;10m"
// EntryReader prints the decrypted contents of a libmutton entry in a human-readable format // EntryReader prints the decrypted contents of a libmutton entry in a human-readable format
// TODO implement password hiding func EntryReader(decryptedEntry []string, hidePassword bool) {
func EntryReader(decryptedEntry []string) {
fmt.Println() fmt.Println()
// track if extended notes have been printed (to avoid printing an extra newline) // track if extended notes have been printed (to avoid printing an extra newline)
@@ -30,7 +31,11 @@ func EntryReader(decryptedEntry []string) {
case 1: case 1:
// if the first field (password) is not empty, print it // if the first field (password) is not empty, print it
if decryptedEntry[0] != "" { if decryptedEntry[0] != "" {
fmt.Print(ansiDirectoryHeader + "Password:" + offline.AnsiReset + "\n" + decryptedEntry[0] + "\n\n") if !hidePassword {
fmt.Print(ansiDirectoryHeader + "Password:" + offline.AnsiReset + "\n" + ansiShownPassword + decryptedEntry[0] + offline.AnsiReset + "\n\n")
} else {
fmt.Print(ansiDirectoryHeader + "Password:" + offline.AnsiReset + "\n" + ansiEmptyDirectoryWarning + "End command in \"show\" or \"-s\" to view" + offline.AnsiReset + "\n\n")
}
} }
case 2: case 2:
// if the third field (url) is not empty, print it // if the third field (url) is not empty, print it
@@ -59,9 +64,9 @@ func EntryReader(decryptedEntry []string) {
os.Exit(0) os.Exit(0)
} }
func EntryReaderShortcut(targetLocation string) { func EntryReaderShortcut(targetLocation string, hidePassword bool) {
if isFile, _ := offline.TargetIsFile(targetLocation, true); isFile { if isFile, _ := offline.TargetIsFile(targetLocation, true); isFile {
EntryReader(offline.DecryptGPG(targetLocation)) EntryReader(offline.DecryptGPG(targetLocation), hidePassword)
} else { } else {
fmt.Println(offline.AnsiError + "Failed to read \"" + targetLocation + "\" - it is a directory" + offline.AnsiReset) fmt.Println(offline.AnsiError + "Failed to read \"" + targetLocation + "\" - it is a directory" + offline.AnsiReset)
} }