change read password method

ws
dingjun 4 years ago
parent 650abc6734
commit d8a19c9c82

@ -14,13 +14,13 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/bgentry/speakeasy"
"github.com/fangdingjun/go-log/v5" "github.com/fangdingjun/go-log/v5"
"github.com/fangdingjun/obfssh" "github.com/fangdingjun/obfssh"
"github.com/kr/fs" "github.com/kr/fs"
"github.com/pkg/sftp" "github.com/pkg/sftp"
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent" "golang.org/x/crypto/ssh/agent"
"golang.org/x/crypto/ssh/terminal"
) )
type options struct { type options struct {
@ -577,8 +577,10 @@ func makeDirs(p string, c dirInterface) error {
func passwordAuth() (string, error) { func passwordAuth() (string, error) {
// read password from console // read password from console
s, err := speakeasy.Ask("Password: ") fmt.Fprintf(os.Stdout, "Password: ")
return strings.Trim(s, " \r\n"), err s, err := terminal.ReadPassword(int(os.Stdin.Fd()))
fmt.Fprintf(os.Stdout, "\n")
return strings.Trim(string(s), " \r\n"), err
} }
// //

@ -11,11 +11,11 @@ import (
"strings" "strings"
"time" "time"
"github.com/bgentry/speakeasy"
"github.com/fangdingjun/go-log/v5" "github.com/fangdingjun/go-log/v5"
"github.com/fangdingjun/obfssh" "github.com/fangdingjun/obfssh"
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent" "golang.org/x/crypto/ssh/agent"
"golang.org/x/crypto/ssh/terminal"
) )
var dialer = &net.Dialer{Timeout: 15 * time.Second} var dialer = &net.Dialer{Timeout: 15 * time.Second}
@ -383,8 +383,10 @@ func keyboardAuth(user, instruction string, question []string, echos []bool) (an
func passwordAuth() (string, error) { func passwordAuth() (string, error) {
// read password from console // read password from console
s, err := speakeasy.Ask("Password: ") fmt.Fprintf(os.Stdout, "Password: ")
return strings.Trim(s, " \r\n"), err s, err := terminal.ReadPassword(int(os.Stdin.Fd()))
fmt.Fprintf(os.Stdout, "\n")
return strings.Trim(string(s), " \r\n"), err
} }
func usage() { func usage() {

Loading…
Cancel
Save