27 lines
473 B
Go
27 lines
473 B
Go
package credentials
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"golang.org/x/term"
|
|
)
|
|
|
|
func Read() (string, string, error) {
|
|
fmt.Print("Enter username: ")
|
|
reader := bufio.NewReader(os.Stdin)
|
|
username, _ := reader.ReadString('\n')
|
|
username = strings.TrimSpace(username)
|
|
|
|
fmt.Printf("password for %s: ", username)
|
|
password, err := term.ReadPassword(int(os.Stdin.Fd()))
|
|
if err != nil {
|
|
return "", "", err
|
|
}
|
|
fmt.Println()
|
|
|
|
return username, string(password), nil
|
|
}
|