golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.9k stars 17.65k forks source link

x/crypto/ssh/terminal: terminal.ReadPassword doesn't work when using Bash for Windows (from Git installation) #34612

Open Hades32 opened 5 years ago

Hades32 commented 5 years ago

What version of Go are you using (go version)?

$ go version
go version go1.12.5 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\mrausc\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\mrausc\go
set GOPROXY=
set GORACE=
set GOROOT=C:\MyProgs\Go
set GOTMPDIR=
set GOTOOLDIR=C:\MyProgs\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=X:\swda\play\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\mrausc\AppData\Local\Temp\go-build325358090=/tmp/go-build -gno-record-gcc-switches

What did you do?

func main() {
    _, err := terminal.ReadPassword(int(os.Stdin.Fd()))
    fmt.Println(err)
}

What did you expect to see?

no echo of password

What did you see instead?

"The handle is invalid."

bcmills commented 5 years ago

CC @hanwen @FiloSottile

Or-Geva commented 5 years ago

I got the same issue.

mattn commented 4 years ago

Do you use third-party terminal application? If you use mintty, an application which use Windows Console APIs does not work. you must use winpty to run the application.

EtienneM commented 2 years ago

We are facing the same issue but found out something slightly odd. First, we use the new golang.org/x/term package rather than x/crypto/ssh/terminal as mentioned in the title of this issue.

We face the same issue as described in this issue in Git Bash. The code is here: https://github.com/Scalingo/cli/blob/master/term/password.go#L13

But if we run Git Bash from within the terminal tab of VS Code, we no longer face the same issue, everything works as expected.

Does anyone know what is the difference between Git Bash and Git Bash inside VS Code?

mattn commented 2 years ago

I can't reproduce this. Windows 11 21H2 64Bit amd64.

EtienneM commented 2 years ago

I uploaded the smallest example which reproduces the issue here: https://github.com/EtienneM/mwe_read_password/blob/master/main.go

I'm not exactly sure about what information may be needed. My OS version:

C:\Users\Administrator>systeminfo | findstr /B /C:"OS Name" /C:"OS Version"

OS Name:                   Microsoft Windows Server 2019 Datacenter
OS Version:                10.0.17763 N/A Build 17763

The Go version:

C:\Users\Administrator>go version
go version go1.19.2 windows/amd64

The golang.org/x/term version is:

$ cat go.mod | grep "golang.org/x/term"
require golang.org/x/term v0.0.0-20220919170432-7a66f970e087

With this example, in Git Bash in VS Code I can type a password and the output is:

$ go build && ./mwe.exe
<nil>

In Git Bash outside of VS Code, I can't type the password and immediately get the error:

$ go build && ./mwe.exe
The handle is invalid.
sunshine69 commented 2 years ago

I hit this problem as well. Run on mingw64 shell - If I run on windows cmd then it works. It is both on window 8 and windows 10 at my work place.