1
def check_password(x):
while x != ("admin123"):
    x = input("incorrect password \ntry again:")
return x

password = input("please type the password: ")
password = check_password(password)
print ("correct password")

I am trying to replace each character of the user's input with asterisks (*) in IDLE terminal for security reasons, as the user will be inputting a password. I have found some alternatives such as the getpass() module, but the getpass() does not display anything for the user on the terminal IDLE to tell him that he/she is typing. Therefore, I have decided to look for a replacement solution instead of getpass().

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Y.Hasan
  • 11
  • 7
  • @Gary The solution there is not working for me as I am using IDLE on windows, it displays (No module named 'termios'), so that is not the solution of my question. – Y.Hasan Feb 07 '16 at 01:24
  • @Y.Hasan a little google search got me [this](http://stackoverflow.com/questions/933745/what-is-the-windows-equivalent-to-the-capabilities-defined-in-sys-select-h-and-t). May be that will help. And yeah, sometimes this duplicate flagging thing kills actual non-duplicate questions `:-(` – Sнаđошƒаӽ Feb 08 '16 at 19:55
  • You probably cannot expect to do this in IDLE. Anywhere that IDLE can be used, the command line can be as well. – Karl Knechtel Aug 03 '22 at 03:40

1 Answers1

0

I have wrote this code and it did the job for me

just take the input from the user as series of characters via getch()

which is not printing the output then print * instead after each input

import sys
import msvcrt

passwor = ''
while True:
    x = msvcrt.getch()
    if x == '\r':
        break
    sys.stdout.write('*')
    passwor +=x

print '\n'+passwor
Ahmed ALaa
  • 217
  • 2
  • 3