Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix: rely on term.ReadPassword for password prompts#84

Merged
balajz merged 3 commits into
balajz:mainbalajz/pgxcli:mainfrom
GHX5T-SOL:fix/82-password-prompt-readpasswordGHX5T-SOL/pgxcli:fix/82-password-prompt-readpasswordCopy head branch name to clipboard
May 28, 2026
Merged

fix: rely on term.ReadPassword for password prompts#84
balajz merged 3 commits into
balajz:mainbalajz/pgxcli:mainfrom
GHX5T-SOL:fix/82-password-prompt-readpasswordGHX5T-SOL/pgxcli:fix/82-password-prompt-readpasswordCopy head branch name to clipboard

Conversation

@GHX5T-SOL

Copy link
Copy Markdown
Contributor

Closes #82.

Summary

  • let term.ReadPassword manage terminal password console modes directly instead of putting stdin into raw mode first
  • keep a non-terminal fallback that reads the full password line and handles CRLF input
  • add coverage for fallback passwords containing spaces

Validation

  • go test ./internal/cli -run TestPromptPasswordFallsBackToFullLineInput -count=1
  • go test ./internal/cli
  • go test ./internal/database
  • go test ./...
  • go build -o /tmp/pgxcli-opp148 ./cmd/pgxcli
  • make build
  • go vet ./...
  • ./bin/app --help
  • git diff --check
  • git diff --cached --check
  • changed and staged diff gitleaks scans

Not run

  • make lint because golangci-lint is not installed locally (make: golangci-lint: No such file or directory).
  • Windows console smoke; validation was run on macOS/darwin amd64.

@balajz

balajz commented May 26, 2026

Copy link
Copy Markdown
Owner

I think the problem is with these lines

pgxcli/internal/cli/root.go

Lines 322 to 329 in 91d6987

cliCtx.Logger.Debug("Connection failed, prompting for password")
if wErr := renderer.Error(
fmt.Errorf("Wrong password, try again."), //nolint // user-facing message
os.Stderr,
); wErr != nil {
return wErr
}
, on windows (no / disabled unixsocket system), if no password is entered, mentioned function connects with password = "" (empty string), then it fails and printing "wrong password, try again".

@GHX5T-SOL

Copy link
Copy Markdown
Contributor Author

Thanks, that points to the missing part. I pushed db27cad to avoid the initial empty-password connection attempt on Windows when no password/env value is available.

What changed:

  • --password still prompts first and does not prompt twice.
  • --no-password still avoids prompting and uses PGXPASSWORD / PGPASSWORD when available.
  • Unix keeps the existing passwordless-first attempt for socket/trust setups.
  • Windows now prompts before connecting with an empty password, which avoids the immediate Wrong password, try again. path from the first attempt.

Validation:

  • go test ./internal/cli
  • go test ./...
  • git diff --check
  • git diff --no-ext-diff | gitleaks stdin --no-banner --redact --exit-code 1

@balajz

balajz commented May 28, 2026

Copy link
Copy Markdown
Owner

Let me explain the workflow. When I tries to connect without a password, it should first attempt a Unix socket connection with no password. If the connection succeeds, everything proceeds normally.

If it fails due to an authentication error, we then prompt the user to enter a password, but we don’t prompt that the previous attempt failed, since the user never actually entered a password.

The application should then try to connect again, making it appear to the user as if this is the first connection attempt.

@GHX5T-SOL

Copy link
Copy Markdown
Contributor Author

Thanks, that workflow makes sense. I pushed bda9634 to restore the passwordless first connection attempt and only suppress the warning when that first failed auth attempt used an empty password.

Behavior now:

  • no password provided: try the initial connection first; if it fails with auth error, prompt with Enter password and retry without printing Wrong password, try again.
  • password/env/forced prompt provided: keep the existing wrong-password warning and Enter password again retry path
  • --no-password still returns the auth failure without prompting

Validation:

  • go test ./internal/cli
  • go test ./...
  • git diff --check
  • git diff --no-ext-diff | gitleaks stdin --no-banner --redact --exit-code 1

@balajz
balajz merged commit d9ea608 into balajz:main May 28, 2026
8 checks passed
@balajz

balajz commented May 28, 2026

Copy link
Copy Markdown
Owner

Thank you for your contribution. I’d love to see more contributions from you in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Password prompt skipped; immediately throws wrong password error

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.