You can take the input from the user as series of characters via getch()
then print * instead after each input
[EDIT]:
Forgot to handle the backspace key: -
Please refer to the below more robust code:
import sys
import msvcrt
def encriptAndsavePassword():
password = ''
while True:
x = ord(msvcrt.getch())
if x == 13:
# When system receives a carriage return character
sys.stdout.write('\n')
return password
elif x == 8:
if len(password) > 0:
# Deletes previous character.
sys.stdout.write('\b' + ' ' + '\b')
sys.stdout.flush()
password = password[:-1]
else:
sys.stdout.write('*')
password +=x
you can read about getch()
from here