Masking a string input

Reply

Join Date: Mar 2007
Posts: 6
Reputation: Gumster is an unknown quantity at this point 
Solved Threads: 0
Gumster Gumster is offline Offline
Newbie Poster

Masking a string input

 
0
  #1
Mar 21st, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 148
Reputation: ghostdog74 is on a distinguished road 
Solved Threads: 40
ghostdog74 ghostdog74 is offline Offline
Junior Poster

Re: Masking a string input

 
0
  #2
Mar 21st, 2007
Originally Posted by Gumster View Post
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.
  1. import getpass
  2. pswd = getpass.getpass("enter password: ")
  3. print pwd
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 608
Reputation: jrcagle is on a distinguished road 
Solved Threads: 150
jrcagle jrcagle is offline Offline
Practically a Master Poster

Re: Masking a string input

 
0
  #3
Mar 21st, 2007
or if you are using Tkinter Entry widgets, you can set the parameter

show='*'
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 6
Reputation: Gumster is an unknown quantity at this point 
Solved Threads: 0
Gumster Gumster is offline Offline
Newbie Poster

Re: Masking a string input

 
0
  #4
Mar 22nd, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 608
Reputation: jrcagle is on a distinguished road 
Solved Threads: 150
jrcagle jrcagle is offline Offline
Practically a Master Poster

Re: Masking a string input

 
0
  #5
Mar 23rd, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 148
Reputation: ghostdog74 is on a distinguished road 
Solved Threads: 40
ghostdog74 ghostdog74 is offline Offline
Junior Poster

Re: Masking a string input

 
0
  #6
Mar 24th, 2007
maybe you can try this . Not tested
  1.  
  2. def invisible():
  3. key = ''
  4. passwd = ''
  5. max_char = 8
  6. while 1 :
  7. key = msvcrt.getch()
  8. if key == '\r': break
  9. passwd = passwd + key
  10. if len(passwd) == max_char:
  11. break
  12. msvcrt.putch('*')
Last edited by ghostdog74; Mar 24th, 2007 at 3:21 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC