From c6af292b2a96a34eaa7176cb7ba27af5460d3b76 Mon Sep 17 00:00:00 2001 From: Christopher Davis Date: Thu, 5 Sep 2019 17:23:30 -0700 Subject: [PATCH 1/3] Add password flag for authentication For T692 --- cmd/writeas/main.go | 4 ++++ commands/commands.go | 20 ++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cmd/writeas/main.go b/cmd/writeas/main.go index e9c1019..40bff74 100644 --- a/cmd/writeas/main.go +++ b/cmd/writeas/main.go @@ -238,6 +238,10 @@ func main() { Name: "verbose, v", Usage: "Make the operation more talkative", }, + cli.StringFlag{ + Name: "password, p", + Usage: "The password for the account being logged into", + }, }, }, { diff --git a/commands/commands.go b/commands/commands.go index 29ddc21..c2fc3a8 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -408,15 +408,19 @@ func CmdAuth(c *cli.Context) error { } } - fmt.Print("Password: ") - pass, err := gopass.GetPasswdMasked() - if err != nil { - return cli.NewExitError(fmt.Sprintf("error reading password: %v", err), 1) - } - - // Validate password + // Take password from argument, and fall back to input + pass := c.String("p") if len(pass) == 0 { - return cli.NewExitError("Please enter your password.", 1) + fmt.Print("Password: ") + pass, err := gopass.GetPasswdMasked() + if err != nil { + return cli.NewExitError(fmt.Sprintf("error reading password: %v", err), 1) + } + + // Validate password + if len(pass) == 0 { + return cli.NewExitError("Please enter your password.", 1) + } } if config.IsTor(c) { From f2bb9f5896df03fb191b88af0ed3b05fd47a4365 Mon Sep 17 00:00:00 2001 From: Christopher Davis Date: Fri, 6 Sep 2019 09:51:02 -0700 Subject: [PATCH 2/3] commands: Fix up the interactive auth flow Fixes up the interactive authorization workflow so that pass is reassigned properly. For T692 --- commands/commands.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/commands/commands.go b/commands/commands.go index c2fc3a8..a87a582 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -410,17 +410,18 @@ func CmdAuth(c *cli.Context) error { // Take password from argument, and fall back to input pass := c.String("p") - if len(pass) == 0 { + if pass == "" { fmt.Print("Password: ") - pass, err := gopass.GetPasswdMasked() + enteredPass, err := gopass.GetPasswdMasked() if err != nil { return cli.NewExitError(fmt.Sprintf("error reading password: %v", err), 1) } // Validate password - if len(pass) == 0 { + if len(enteredPass) == 0 { return cli.NewExitError("Please enter your password.", 1) } + pass = string(enteredPass) } if config.IsTor(c) { From bd378a85ad6389a882eff2610e64a272ce0d0aca Mon Sep 17 00:00:00 2001 From: Christopher Davis Date: Tue, 8 Oct 2019 18:34:37 -0700 Subject: [PATCH 3/3] commands: Remove redundant string() cast on pass When logging in we had a cast that was made redundant, since `pass` is now a string. --- commands/commands.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/commands.go b/commands/commands.go index a87a582..d6a55d6 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -429,7 +429,7 @@ func CmdAuth(c *cli.Context) error { } else { log.Info(c, "Logging in...") } - err = api.DoLogIn(c, username, string(pass)) + err = api.DoLogIn(c, username, pass) if err != nil { return cli.NewExitError(fmt.Sprintf("error logging in: %v", err), 1) }