Hide password on terminal [duplicate]

5

I'm developing a python application that will work through the terminal

At some point, I need to login:

print('É necessário informar suas credenciais para se comunicar com a API')
email = input('Email: ')
password = input('Senha: ')

The problem is that the output on the console looks like this:

É necessário informar suas credenciais para se comunicar com a API:
Email: [email protected]
Senha: senhaTeste

I need the password field not to display the characters, to replace with "*" or something like:

The output that I look for in the terminal is something like this:

É necessário informar suas credenciais para se comunicar com a API:
Email: [email protected]
Senha: **********
    
asked by anonymous 21.07.2017 / 15:40

2 answers

5

You can use getpass.getpass

import getpass

print('É necessário informar suas credenciais para se comunicar com a API')
email = input('Email: ')
password = getpass.getpass('Senha: ')
    
21.07.2017 / 15:48
1

If you want this to happen on the terminal , you will have to create a new input function and then import it from the original input () function in C (available here from line 1832) . It seems to be relatively easy if you understand a bit how the compiler works. So far as I know, there is still no high-level solution to this problem.

    
21.07.2017 / 16:57