0

I'm writing a command line tool with Go and one of the command will query the user for its username and password (and save it to a config file inside the home directory).

For now I couldn't realize how to replace the typed password to '*' or even not to type anything as a lot of command line tools are doing.

How does can this be done when using golang?

Shikloshi
  • 3,761
  • 7
  • 32
  • 58

1 Answers1

0

Type this stuff into Google before you come here.

you can do this by execing stty -echo to turn off echo and then stty echo after reading in the password to turn it back on

OR

Just saw a mail in #go-nuts maillist. There is someone who wrote quite a simple go package to be used. You can find it here: https://github.com/howeyc/gopass

It something like that:

package main

import "fmt" import "github.com/howeyc/gopass"

func main() {
    fmt.Printf("Password: ")
    pass := gopass.GetPasswd()
    // Do something with pass }

Taken from another Stackoverflow post.

Community
  • 1
  • 1
abalos
  • 1,301
  • 7
  • 12