INNER CODE UNIT · Go

readPasswordFromStdin

umputun/spot · cmd/secrets/main.go:159

func readPasswordFromStdin(prompt string) (string, error) {
	// check if stdin is a terminal
	if !term.IsTerminal(int(os.Stdin.Fd())) {
		// not a terminal, read directly (for piped input)
		var password string
		if _, err := fmt.Scanln(&password); err != nil && err != io.EOF {
			return "", err
		}
		return password, nil
	}

	// terminal input, use secure password reading
	fmt.Fprint(os.Stderr, prompt)
	passwordBytes, err := term.ReadPassword(int(os.Stdin.Fd()))
	if err != nil {
		return "", err
	}
	fmt.Fprintln(os.Stderr) // print newline after password input

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…