Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enter hidden password in python

I want to use:

import getpass
password = getpass.getpass("Enter your password:")
print password

On winx64 using python 2.7... The 2nd line hangs. I dont see the dialog. " Enter your password:"

like image 845
Merlin Avatar asked Apr 13 '12 14:04

Merlin


People also ask

How to hide the user ID and password in Python?

I will need the config function found in the ‘decouple’ module in python to hide the password. To install this module, run the following command on your terminal: After this gets installed, make a .env file in the same folder as our test.py file, and copy-paste the userID and password in that file, like this,

What is the default password for getpass in Python?

"Password: " (with a space after the colon) is the default prompt, so there's often no need to specify it in the call to getpass.getpass (). this gave me an error Warning (from warnings module): File "C:\Python27\lib\getpass.py", line 92 return fallback_getpass (prompt, stream) GetPassWarning: Can not control echo on the terminal.

How do I get user input with Python?

Getting user input with Python is pretty easy. You make a call to input, and whatever the user types is stored as a variable: My problem was when I typed a password into the terminal in response to my password prompt, everything I typed was visible to anyone looking over my shoulder or scrolling through my terminal history:

How to hide secrets from the public in Python?

In order to make applications more secure and make these secrets hidden from everyone, it's also better to use the secrets as an environment variable or config file. In Python, there are various packages that can be used for this like: python-decouple , python-dotenv , jproperties. Let's deep dive into each of them to understand the flow and usage.


2 Answers

According to your comment above, you are actually using ipython within spyder. The only issue I came across for getpass in Spyder is at their Google code page. The issues is not exactly the same as yours, but included in the comments is the following code snippet:

def spyder_getpass(prompt='Password: '):
  set_spyder_echo(False)
  password = raw_input(prompt)
  set_spyder_echo(True)
  return password

Try using the method above (utilizing raw_input instead of getpass) to get the required password you need.

like image 140
PenguinCoder Avatar answered Oct 16 '22 21:10

PenguinCoder


As the other comments already indicated, you have to run this script within the Power Shell to actually see the "Enter your password:" text and be able to enter a password.

like image 2
cfedermann Avatar answered Oct 16 '22 20:10

cfedermann