File: password.go

package info (click to toggle)
golang-github-liamg-clinch 1.5.6-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 5,576 kB
  • sloc: makefile: 2
file content (30 lines) | stat: -rw-r--r-- 941 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package prompt

import (
	"syscall"

	"github.com/liamg/clinch/terminal"
	sshterm "golang.org/x/crypto/ssh/terminal"
)

// EnterPassword requests input from the user with the given message, hiding that input, and returns any user input that was gathered until a newline was entered
func EnterPassword(msg string) string {
	terminal.ClearLine()
	terminal.PrintImportantf(msg)
	bytePassword, err := sshterm.ReadPassword(int(syscall.Stdin))
	if err != nil {
		return ""
	}
	return string(bytePassword)
}

// EnterPasswordE requests input from the user with the given message, hiding that input, and returns any user input that was gathered until a newline was entered - returning an error if one occurred
func EnterPasswordE(msg string) (string, error) {
	terminal.ClearLine()
	terminal.PrintImportantf(msg)
	bytePassword, err := sshterm.ReadPassword(int(syscall.Stdin))
	if err != nil {
		return "", err
	}
	return string(bytePassword), nil
}