Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prompt_pass not working on windows when using CTRL+V to paste the password string to console #160

Open
atbagga opened this issue Jun 27, 2019 · 2 comments

Comments

@atbagga
Copy link
Contributor

atbagga commented Jun 27, 2019

Issue: prompt_pass is not working on windows with CTRL+V being used to enter the input

Repro:

### CODE PART 1 ###
# ** getpass_fails.py ** #

from knack.prompting import prompt_pass
password = prompt_pass(msg="Password: ")
print(password)

Steps to repro:

  1. Copy a text to clipboard using CTRL+C e.g. "mypassword"
  2. On CMD or powershell prompt python getpass_fails.py
  3. On Password: prompt use CTRL+V to paste the copied text.

Actual Behavior:
image

Expected Behavior:
image

WORKAROUND: The issue in only in using Ctrl+V to paste. If we use console menu or right click to paste it works correctly.

@atbagga
Copy link
Contributor Author

atbagga commented Jun 27, 2019

This is heavily used in Azure CLI and its extensions. Azure-devops extension uses this function to accept Personal Access Token for login. Since it is an arbitrary long string people are used to using Ctrl+v for it.

Although the issue is in getpass library code.. Not sure where to follow up on it.
Confirmed by reproducing the above behavior using these code snippets:

### CODE PART 2 - Issue using getpass ###
# import getpass
# password = getpass.getpass(prompt="Password: ")
# print(password)

### CODE PART 3 - Issue using  win_getpass function from the getpass module ###
# import msvcrt
# def win_getpass(prompt='Password: ', stream=None):
#     """Prompt for password with echo off, using Windows getch()."""
#     for c in prompt:
#         msvcrt.putwch(c)
#     pw = ""
#     while 1:
#         c = msvcrt.getwch()
#         if c == '\r' or c == '\n':
#             break
#         if c == '\003':
#             raise KeyboardInterrupt
#         if c == '\b':
#             pw = pw[:-1]
#         else:
#             pw = pw + c
#     msvcrt.putwch('\r')
#     msvcrt.putwch('\n')
#     return pw


# password = win_getpass(prompt="Password: ")
# print(password)

@tjprescott

@atbagga
Copy link
Contributor Author

atbagga commented Jun 27, 2019

Also created an issue - https://bugs.python.org/issue37426 for this.

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

No branches or pull requests

2 participants