diff options
author | Amjith Ramanujam <amjith.r@gmail.com> | 2019-03-23 10:12:12 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-23 10:12:12 -0700 |
commit | a7632361c42b33e4474a4ca5363bddbf57484daa (patch) | |
tree | ec8ea608b578ad6a2953a4182ed0ca1f96fcbe06 | |
parent | d8df2cc03b8b83061786027c1def3a0edd02f05c (diff) | |
parent | b0529bcc4f04d7e11bafa54def69a3c1a07a901d (diff) |
Merge pull request #1028 from dbcli/j-bennet/update-keyring-password
Ask for password in case of incorrect password.
-rw-r--r-- | changelog.rst | 1 | ||||
-rw-r--r-- | pgcli/main.py | 21 |
2 files changed, 15 insertions, 7 deletions
diff --git a/changelog.rst b/changelog.rst index 7db254c5..2667c11e 100644 --- a/changelog.rst +++ b/changelog.rst @@ -14,6 +14,7 @@ Bug fixes: * Resizing pgcli terminal kills the connection to postgres in python 2.7 (Thanks: `Amjith Ramanujam`_) * Fix crash retrieving server version with ``--single-connection``. (Thanks: `Irina Truong`_) * Cannot quit application without reconnecting to database (#1014). (Thanks: `Irina Truong`_) +* Password authentication failed for user "postgres" when using non-default password (#1020). (Thanks: `Irina Truong`_) Internal: --------- diff --git a/pgcli/main.py b/pgcli/main.py index 8078c5ce..d7853e47 100644 --- a/pgcli/main.py +++ b/pgcli/main.py @@ -443,21 +443,28 @@ class PGCli(object): passwd = click.prompt('Password for %s' % user, hide_input=True, show_default=False, type=str) - # Prompt for a password after 1st attempt to connect without a password - # fails. Don't prompt if the -w flag is supplied - auto_passwd_prompt = not passwd and not self.never_passwd_prompt + def should_ask_for_password(exc): + # Prompt for a password after 1st attempt to connect + # fails. Don't prompt if the -w flag is supplied + if self.never_passwd_prompt: + return False + error_msg = utf8tounicode(exc.args[0]) + if "no password supplied" in error_msg: + return True + if "password authentication failed" in error_msg: + return True + return False # Attempt to connect to the database. # Note that passwd may be empty on the first attempt. If connection - # fails because of a missing password, but we're allowed to prompt for - # a password (no -w flag), prompt for a passwd and try again. + # fails because of a missing or incorrect password, but we're allowed to + # prompt for a password (no -w flag), prompt for a passwd and try again. try: try: pgexecute = PGExecute(database, user, passwd, host, port, dsn, application_name='pgcli', **kwargs) except (OperationalError, InterfaceError) as e: - if ('no password supplied' in utf8tounicode(e.args[0]) and - auto_passwd_prompt): + if should_ask_for_password(e): passwd = click.prompt('Password for %s' % user, hide_input=True, show_default=False, type=str) |