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?
Asked
Active
Viewed 942 times
0
-
For a console application, it's best to use the getpass module even though it doesn't change the typed characters into asterisks. – Jayanth Koushik Mar 11 '14 at 09:16
-
Are you sure you want `*` to be echoed? Would having the display of the keypresses suppressed suffice? – MattH Mar 11 '14 at 09:17
-
Yeah suppressing the keypresses would work but How? – 0llie_C Mar 11 '14 at 09:19
2 Answers
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