diff options
author | Irina Truong <i.chernyavska@gmail.com> | 2019-03-22 16:49:54 +0000 |
---|---|---|
committer | Irina Truong <i.chernyavska@gmail.com> | 2019-03-22 16:49:54 +0000 |
commit | 3f0e47d7b3049bfd75ee54bc7643dd462bf6f615 (patch) | |
tree | a77ea57288a87ad790d4dc4882e8ffd4389d810b | |
parent | d8df2cc03b8b83061786027c1def3a0edd02f05c (diff) |
Ask for password in case of incorrect password.
-rw-r--r-- | pgcli/main.py | 21 |
1 files changed, 14 insertions, 7 deletions
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) |