askpassword

package module
v0.0.0-...-31e84f3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2024 License: MIT Imports: 9 Imported by: 1

README

go-ask-password

systemd-ask-password like password prompt for go

example usage

pw, err := AskPassword.AskPassword("Password: ")
if err != nil {
	log.Fatal(err)
}
fmt.Println(pw)

also in demo/password.go and demo/substitute.go


This project is mostly based around mattn's go-tty.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AskKey

func AskKey(prefix string) (string, error)

AskKey is an opinionated default Password prompt like systemd-ask-password

func AskPassword

func AskPassword(prefix string) (string, error)

AskPassword is an opinionated default Password prompt like systemd-ask-password

func AskUser

func AskUser(prefix string) (string, error)

AskUser is an opinionated default Username prompt

func NewScan

func NewScan(opts Options) (string, error)

NewScan starts a new scanner with the given options.

func Scan

func Scan(prefix string) (string, error)

Scan takes (printable) input until a newline is entered.

func ScanSecret

func ScanSecret(prefix string, substitute string, placeholder string) (string, error)

ScanSecret takes (printable) input till a newline is entered but hides the content by default.

Types

type Options

type Options struct {
	Plain bool // does not hide the password if true

	Prefix      string // whats shown in front of the password field
	Substitute  string // character/string shown instead of the password input
	Placeholder string // whats shown while there has not been user input yet

	BreakAt           rune // character that closes/exits the prompt (def: 13 / enter)
	ExitOnUnprintable bool // exit with an error if an unprintable character is entered, will ignore them if false
	MaxLength         int  // maximum input length (def: none)
}

Directories

Path Synopsis
nolint
nolint

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL