Hi all, im gumster new to DaniWeb, been programming vb for numerous years moving to python anyway, Im trying to create a small authentication module for a program im making where it asks for the username and password, i was just wondering how i go about masking the password
so say for instance the password was "foo" when the user types on there keyboard all that is displayed is "***"?

Any help would be appreciated

Hi all, im gumster new to DaniWeb, been programming vb for numerous years moving to python anyway, Im trying to create a small authentication module for a program im making where it asks for the username and password, i was just wondering how i go about masking the password
so say for instance the password was "foo" when the user types on there keyboard all that is displayed is "***"?

Any help would be appreciated

you can use the getpass module.

import getpass
pswd = getpass.getpass("enter password: ")
print pwd

or if you are using Tkinter Entry widgets, you can set the parameter

show='*'

The getpass function wont work it doesnt mask anything it merely just stops the program from echoing the string input it doesnt offer options for any masking
as for tkinter this doesnt really suit either im not wanting a GUI.

Is there any other possible way

I couldn't even get 'getpass' to work in windows (passwords get echoed), so there it is.

If you're using linux, you could try copying the getpass code and modifying it to echo a masking character.


Jeff

maybe you can try this . Not tested

def invisible():
	key = ''
	passwd = ''
	max_char = 8
	while 1 :
		key = msvcrt.getch()
		if key == '\r': break
		passwd = passwd + key
		if len(passwd) == max_char:
			break
		msvcrt.putch('*')
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.