From 94f3a136979f6d82845d028b55ef633a5546836d Mon Sep 17 00:00:00 2001 From: Hyerbwert Twielen Date: Tue, 20 Jun 2023 14:45:33 +0200 Subject: [PATCH] made twis luscious toow wowk witw a passwowd fiwe, to enyabwe it to wowk compwetewy nyon-intewactivwy --- cmd/lsf/main.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/cmd/lsf/main.go b/cmd/lsf/main.go index 6e4c347..f9e90c5 100644 --- a/cmd/lsf/main.go +++ b/cmd/lsf/main.go @@ -3,10 +3,11 @@ package main import ( "fmt" - "io/ioutil" + "io/ioutil" "log" "os" "path" + "path/filepath" "strings" "syscall" @@ -84,6 +85,24 @@ func readUsername() (string, error) { func readPassword() (string, error) { var password string + + configDir := filepath.Join(os.Getenv("HOME"), ".config", "lsfshutthefuckup") + configPath := filepath.Join(configDir, "credentials") + + // Check if the credentials file exists + if _, err := os.Stat(configPath); err == nil { + // Read the password from the file + content, err := ioutil.ReadFile(configPath) + if err != nil { + return "", err + } + + // Extract the password value from the file content + password := extractPassword(content) + print(password) + return password, nil + } + fmt.Fprint(os.Stderr, "Password: ") b, err := terminal.ReadPassword(int(syscall.Stdin)) if err != nil { @@ -94,6 +113,16 @@ func readPassword() (string, error) { return password, nil } +func extractPassword(content []byte) string { + lines := strings.Split(string(content), "\n") + for _, line := range lines { + if strings.HasPrefix(line, "password=") { + return strings.TrimPrefix(line, "password=") + } + } + return "" +} + func session(username string) (*lsf.Session, error) { sessionPath := path.Join(*sessionCacheDir, username)