954,198 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Masking a string input

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

Gumster
Newbie Poster
6 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

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
ghostdog74
Junior Poster
156 posts since Apr 2006
Reputation Points: 75
Solved Threads: 44
 

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

show='*'

jrcagle
Practically a Master Poster
608 posts since Jul 2006
Reputation Points: 92
Solved Threads: 156
 

[INDENT]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
[/INDENT]

Gumster
Newbie Poster
6 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

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

jrcagle
Practically a Master Poster
608 posts since Jul 2006
Reputation Points: 92
Solved Threads: 156
 

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('*')
ghostdog74
Junior Poster
156 posts since Apr 2006
Reputation Points: 75
Solved Threads: 44
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You