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 (
"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