Use mcdsl/terminal.ReadPassword for secure password input
Replaces raw bufio.Scanner password reading (which echoed to terminal) with the new mcdsl terminal package that suppresses echo via x/term. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"git.wntrmute.dev/mc/mcdsl/terminal"
|
||||
"git.wntrmute.dev/mc/mcp/internal/auth"
|
||||
"git.wntrmute.dev/mc/mcp/internal/config"
|
||||
)
|
||||
@@ -33,14 +34,11 @@ func loginCmd() *cobra.Command {
|
||||
}
|
||||
username := strings.TrimSpace(scanner.Text())
|
||||
|
||||
fmt.Print("Password: ")
|
||||
if !scanner.Scan() {
|
||||
if err := scanner.Err(); err != nil {
|
||||
return fmt.Errorf("read password: %w", err)
|
||||
}
|
||||
return fmt.Errorf("read password: unexpected end of input")
|
||||
password, err := terminal.ReadPassword("Password: ")
|
||||
if err != nil {
|
||||
return fmt.Errorf("read password: %w", err)
|
||||
}
|
||||
password := strings.TrimSpace(scanner.Text())
|
||||
password = strings.TrimSpace(password)
|
||||
|
||||
token, err := auth.Login(cfg.MCIAS.ServerURL, cfg.MCIAS.CACert, username, password)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user