Implement terminal style password input

This commit is contained in:
c0re100 2022-01-30 21:48:54 +08:00
parent 7196ad9adc
commit cc7712e2c4
No known key found for this signature in database
GPG key ID: 7C3B3004FE745AAF
3 changed files with 22 additions and 3 deletions

View file

@ -3,7 +3,10 @@ package client
import ( import (
"errors" "errors"
"fmt" "fmt"
"syscall"
"time" "time"
"golang.org/x/crypto/ssh/terminal"
) )
var ErrNotSupportedAuthorizationState = errors.New("not supported state") var ErrNotSupportedAuthorizationState = errors.New("not supported state")
@ -150,10 +153,13 @@ func CliInteractor(clientAuthorizer *clientAuthorizer) {
case TypeAuthorizationStateWaitPassword: case TypeAuthorizationStateWaitPassword:
fmt.Println("Enter password: ") fmt.Println("Enter password: ")
var password string bytePassword, err := terminal.ReadPassword(int(syscall.Stdin))
fmt.Scanln(&password) if err != nil {
fmt.Println(err)
continue
}
clientAuthorizer.Password <- password clientAuthorizer.Password <- string(bytePassword)
case TypeAuthorizationStateReady: case TypeAuthorizationStateReady:
return return

2
go.mod
View file

@ -1,3 +1,5 @@
module github.com/c0re100/gotdlib module github.com/c0re100/gotdlib
go 1.16 go 1.16
require golang.org/x/crypto v0.0.0-20220128200615-198e4374d7ed

11
go.sum Normal file
View file

@ -0,0 +1,11 @@
golang.org/x/crypto v0.0.0-20220128200615-198e4374d7ed h1:YoWVYYAfvQ4ddHv3OKmIvX7NCAhFGTj62VP2l2kfBbA=
golang.org/x/crypto v0.0.0-20220128200615-198e4374d7ed/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=