Most portable way to get password (no echo) from stin

2,123 views
Skip to first unread message

Sam Freiberg

unread,
Jul 9, 2012, 7:16:50 PM7/9/12
to golan...@googlegroups.com
I'm wondering if there is a portable (cross platform) way to get sensitive information from stdin. For example getting a password and not have it echo back when the user types it. Most of the solutions in the archives and github seem to rely on c in some form or another. I've never programmed in c so I might be wrong but it doesn't seem good from a portability aspect and I'd prefer not to have any c in the app if possible.

A web interface will probably be an option for this app but I don't want to have to rely on that. Any help or pointers would be appreciated.

- Sam
Message has been deleted

John

unread,
Jul 9, 2012, 10:32:49 PM7/9/12
to golang-nuts
I can't really say for *portability* between non-nix like systems(aka
windows), but I wrote something to provide this on nix-systems:

http://code.google.com/p/gopass/

It simply issues "stty -echo" before getting the input, with some
extra's for catching signals and returning echo to it's normal state
in case you try to kill the package.

Hope it helps.

--John

Sam Freiberg

unread,
Jul 9, 2012, 11:48:29 PM7/9/12
to Cole Mickens, golan...@googlegroups.com
Getpass requires cgo and OpenSSL so that's a nonstarter. ReadPassword might at least get me all of *NIX platforms which would be a start.

On Jul 9, 2012, at 5:33 PM, Cole Mickens wrote:

This uses Cgo but it (claims to be) portable nonetheless:  https://github.com/gcmurphy/getpass.

There's also this:  http://go.pkgdoc.org/code.google.com/p/go.crypto/ssh/terminal#ReadPassword though I'm unsure of its portability (but a quick peak makes it appear that the source for that function is only built for linux).

Francisco Souza

unread,
Jul 10, 2012, 10:16:48 AM7/10/12
to Sam Freiberg, Cole Mickens, golan...@googlegroups.com
On Tue, Jul 10, 2012 at 12:48 AM, Sam Freiberg <samue...@gmail.com> wrote:
Getpass requires cgo and OpenSSL so that's a nonstarter. ReadPassword might at least get me all of *NIX platforms which would be a start.

ReadPassword works only on Linux, the unique platform with termios support on Go 1.

--
~f

Sebastien Binet

unread,
Jul 10, 2012, 11:33:41 AM7/10/12
to Francisco Souza, Sam Freiberg, Cole Mickens, golan...@googlegroups.com
adding support for darwin wasn't super difficult, once all the leg work
was done in code.google.com/p/go.crypto/ssh/terminal.
see:
https://github.com/sbinet/go-terminal/blob/master/pkg/terminal/termios_darwin_amd64.go

-s

Rich

unread,
Jul 10, 2012, 10:22:41 PM7/10/12
to golan...@googlegroups.com, Francisco Souza, Sam Freiberg, Cole Mickens
go-terminal -- Cool -- Do you have any examples?

Sebastien Binet

unread,
Jul 11, 2012, 3:35:13 AM7/11/12
to Rich, golan...@googlegroups.com, Francisco Souza, Sam Freiberg, Cole Mickens
Rich <rma...@gmail.com> writes:

> go-terminal -- Cool -- Do you have any examples?

not (yet?) in the go-terminal repository but here is how I used it for
go-eval:
https://github.com/sbinet/go-eval/blob/master/cmd/go-eval/eval.go#L78

-s

Jiří Zárevúcky

unread,
Jul 18, 2012, 6:51:05 AM7/18/12
to golan...@googlegroups.com

On Tuesday, 10 July 2012 05:48:29 UTC+2, Sam Freiberg wrote:
Getpass requires cgo and OpenSSL so that's a nonstarter.

 You say you don't want any C in your app because of portability. Let me say that there is nothing non-portable about C itself. Program in C might not be portable because it uses a library that is system-specific, e.g. Win32 API or POSIX libraries (it can also be nonportable to different processors because of bugs and processor intrinsics, but that's irrelevant for most valid programs). Same is true for Go, the only difference is that it already has a platform agnostic comprehensive standard library. OpenSSL is portable, so there is no problem with that as far as I can tell.

Sam Freiberg

unread,
Jul 18, 2012, 11:40:10 AM7/18/12
to Jiří Zárevúcky, golan...@googlegroups.com
I never said there was anything intrinsically non-portable in C. Adding in C code complicates the situation for _me_. Programming in pure Go means I can write code and be relatively sure that it will run on all platforms that Go has been designed to run on even if I haven't tested them myself. Adding in C complicates the issue and it's a complication I'm not willing to accept. I'm not a C programmer and I don't want to be. I'm using Go to get a lot of the advantages of C without the rest of the baggage.

Sam
Reply all
Reply to author
Forward
0 new messages