mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-28 04:46:41 -04:00
Implement initial entry adding (partial, missing notes support)
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/rwinkhart/MUTN/src/offline"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AddPasswordEntry prompts the user for all information relevant to a password entry and writes the entry to an encrypted file at targetLocation
|
||||||
|
func AddPasswordEntry(targetLocation string, hidePassword bool) {
|
||||||
|
_, isAccessible := offline.TargetIsFile(targetLocation, false, 0)
|
||||||
|
if isAccessible {
|
||||||
|
fmt.Println(offline.AnsiError + "Target location already exists" + offline.AnsiReset)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
username := input("Username: ")
|
||||||
|
password := inputHidden("Password: ")
|
||||||
|
url := input("URL: ")
|
||||||
|
// TODO implement notes editor
|
||||||
|
notes := ""
|
||||||
|
|
||||||
|
unencryptedEntry := []string{password, username, url, notes}
|
||||||
|
offline.WriteEntry(targetLocation, unencryptedEntry)
|
||||||
|
fmt.Println(ansiBold + "\nEntry Preview:" + offline.AnsiReset)
|
||||||
|
EntryReader(unencryptedEntry, hidePassword)
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// input prompts the user for input and returns the input as a string
|
||||||
|
func input(prompt string) string {
|
||||||
|
fmt.Print("\n" + prompt)
|
||||||
|
var input string
|
||||||
|
fmt.Scanln(&input)
|
||||||
|
return input
|
||||||
|
}
|
||||||
|
|
||||||
|
// inputHidden prompts the user for input and returns the input as a string, hiding the input from the terminal
|
||||||
|
func inputHidden(prompt string) string {
|
||||||
|
fmt.Print("\n" + prompt)
|
||||||
|
byteInput, _ := terminal.ReadPassword(int(os.Stdin.Fd()))
|
||||||
|
password := string(byteInput)
|
||||||
|
fmt.Println()
|
||||||
|
return password
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user