Implement password hiding in entry readouts

This commit is contained in:
2024-03-01 22:11:59 -05:00
parent 3ed3424adc
commit e822bd89dc
+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)
} }