0

So i am making a program to test a password and was wondering, When the user enters their password can you stop their password from showing as they type it in to the console/GUI?

Bach
  • 6,145
  • 7
  • 36
  • 61
0llie_C
  • 17
  • 4

2 Answers2

2

Python has you covered with a built-in library:

>>> import getpass
>>> pw = getpass.getpass()

Edit: As mentioned by @MattH, this won't echo asterisks (*) while user types the password.

anon582847382
  • 19,907
  • 5
  • 54
  • 57
santosh-patil
  • 1,540
  • 1
  • 15
  • 29
1
import tkinter as tk 

root = tk.Tk()

def store():
    pw = my_box.get()

my_box = tk.Entry(root, show='*')
my_box.pack()
Button(text='Submit', command=store).pack()

root.mainloop()

This will work in a GUI. You can then call pw = my_box.get() where necessary.


You can hide user input in the console using the getpass module- but this only hides and does not display asterisks.

>>> import getpass
>>> pw = getpass.getpass()

But displaying asterisks in the console is a little more complicated; you would need to use sys and msvcrt- Google it or ask a separate question asking how to use these modules for that purpose; I don't know.

anon582847382
  • 19,907
  • 5
  • 54
  • 57