made twis luscious toow wowk witw a passwowd fiwe, to enyabwe it to wowk compwetewy nyon-intewactivwy

This commit is contained in:
Hyerbwert Twielen 2023-06-20 14:45:33 +02:00 committed by Leon Etienne
parent 13c28408f9
commit 94f3a13697

View File

@ -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)