From cc7712e2c44f04c87a3c8180b599ddcb852dcf58 Mon Sep 17 00:00:00 2001 From: c0re100 Date: Sun, 30 Jan 2022 21:48:54 +0800 Subject: [PATCH] Implement terminal style password input --- client/authorization.go | 12 +++++++++--- go.mod | 2 ++ go.sum | 11 +++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 go.sum diff --git a/client/authorization.go b/client/authorization.go index 05aaded..ab08d51 100644 --- a/client/authorization.go +++ b/client/authorization.go @@ -3,7 +3,10 @@ package client import ( "errors" "fmt" + "syscall" "time" + + "golang.org/x/crypto/ssh/terminal" ) var ErrNotSupportedAuthorizationState = errors.New("not supported state") @@ -150,10 +153,13 @@ func CliInteractor(clientAuthorizer *clientAuthorizer) { case TypeAuthorizationStateWaitPassword: fmt.Println("Enter password: ") - var password string - fmt.Scanln(&password) + bytePassword, err := terminal.ReadPassword(int(syscall.Stdin)) + if err != nil { + fmt.Println(err) + continue + } - clientAuthorizer.Password <- password + clientAuthorizer.Password <- string(bytePassword) case TypeAuthorizationStateReady: return diff --git a/go.mod b/go.mod index 84926ec..a591593 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/c0re100/gotdlib go 1.16 + +require golang.org/x/crypto v0.0.0-20220128200615-198e4374d7ed diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..7062305 --- /dev/null +++ b/go.sum @@ -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=