ccclip/pkg/input/password.go

19 lines
391 B
Go
Raw Permalink Normal View History

2023-11-02 07:09:51 +00:00
package input
import (
"fmt"
"os"
"golang.org/x/term"
)
// ReadPassword reads a single line of text from the terminal withouth echoing it out.
func ReadPassword() string {
2023-11-10 16:42:47 +00:00
fmt.Println("Enter your password:")
2023-11-02 07:09:51 +00:00
raw, err := term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
panic(fmt.Sprintf("could not reat password from the terminal: %s", err.Error()))
}
return string(raw)
}