if c == '\x03':
    raise KeyboardInterrupt
if c == '\x08':
    pw = pw[:-1]
else:
    pw = pw + c
stars = random.randint(1, 3)
for i in range(stars):
    msvcrt.putwch('*')
msvcrt.putwch('\r')
msvcrt.putwch('\n')
return pw
How to hide passwd and show ' * ' under Python