Hide Password Input in Python (Simple Trick 😎)

 

In this tutorial, you will learn How to Hide Password Input in Python. This method is quite easier than others. This can be done with 2 lines of python code! Python has a built-in package/module called getpass{code} and this module has a function called getpass{code}. This function hides the inputted password. In windows, it shows nothing while typing password, but in linux, it shows a star (*) instead of password. This thing secure your script more! So let's get started.

{tocify}

Step 1: Import getpass function

I already told you that getpass{code} is a module and under that module there is a function called getpass{code}. we need to import is first. This is a built-in module, so you don't have to worry about it.

from getpass import getpass{codeBox}

Step 2: Use getpass() instead of input() 

getpass(){code} is as same as input(){code}. Default usage: getpass("Your Text Here"){code}

password=getpass('[*] Enter your password: ')
print('Your password is:', password){codeBox}
To check is it working or not, I used print function. you can skip that

Full Code

from getpass import getpass

password=getpass('[*] Enter your password: ')

print('Your password is:', password){codeBox}

Screenshot

Since I'm a Windows user, so it hides the password. If you are on Linux you will see star (*) there.



Post a Comment

Previous Post Next Post