User Input as Password in Python

Hi Guys,

Probably, we can know how to get an input from user using raw_input(); Like in some cases we have to get input from user in authentication process at that time we might be a get user password from user. If user enters the password means it should be invisible to others for that there is an option to get the input depending to password.

We have to import a library called getpass With the help of this library we can get the user input as password. Examples are as follows.


import getpass
pw=getpass.getpass("Enter Your Password Here: ")
if (pw=="password"):
print "You are Welcome..."
else:
print "Sorry! Your are not allowed."

Copy this Code and Paste it in any text editor with file extension of .py; If you execute the code means the terminal waits for user input at “Enter Your Password Here: ” here if you type your password it is invisible to you but it has been storing your password into variable name called pw. After then it has been processed with the string for further Statements. If the condition true means True statements executed other wise false statement will executed.

Output:

password inputIn the figure you can see that cursor waits for user input.

bala@bala-desktop:~$ python pass.py
Enter Your Password Here:
You are Welcome.

Hope that these information is useful for you. 🙂

Thank You. 🙂

With Regards,
V. Balakrishnan.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s