...

Source file src/github.com/mattn/go-tty/_example/password.go

Documentation: github.com/mattn/go-tty/_example

     1  // +build ignore
     2  
     3  package main
     4  
     5  import (
     6  	"encoding/base64"
     7  	"fmt"
     8  
     9  	"github.com/mattn/go-tty"
    10  )
    11  
    12  func main() {
    13  	tty, err := tty.Open()
    14  	defer tty.Close()
    15  
    16  	fmt.Print("Username: ")
    17  	username, err := tty.ReadString()
    18  	if err != nil {
    19  		println("canceled")
    20  		return
    21  	}
    22  	fmt.Print("Password: ")
    23  	password, err := tty.ReadPassword()
    24  	if err != nil {
    25  		println("canceled")
    26  		return
    27  	}
    28  	fmt.Println(base64.StdEncoding.EncodeToString([]byte(username + ":" + password)))
    29  }
    30  

View as plain text