made twis luscious toow wowk witw a passwowd fiwe, to enyabwe it to wowk compwetewy nyon-intewactivwy
This commit is contained in:
parent
13c28408f9
commit
94f3a13697
@ -7,6 +7,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
@ -84,6 +85,24 @@ func readUsername() (string, error) {
|
|||||||
|
|
||||||
func readPassword() (string, error) {
|
func readPassword() (string, error) {
|
||||||
var password string
|
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: ")
|
fmt.Fprint(os.Stderr, "Password: ")
|
||||||
b, err := terminal.ReadPassword(int(syscall.Stdin))
|
b, err := terminal.ReadPassword(int(syscall.Stdin))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -94,6 +113,16 @@ func readPassword() (string, error) {
|
|||||||
return password, nil
|
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) {
|
func session(username string) (*lsf.Session, error) {
|
||||||
|
|
||||||
sessionPath := path.Join(*sessionCacheDir, username)
|
sessionPath := path.Join(*sessionCacheDir, username)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user