944,039 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 4419
  • Python RSS
Mar 21st, 2007
0

Masking a string input

Expand 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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Gumster is offline Offline
6 posts
since Mar 2007
Mar 21st, 2007
0

Re: Masking a string input

Click to Expand / Collapse  Quote originally posted by Gumster ...
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.
Python Syntax (Toggle Plain Text)
  1. import getpass
  2. pswd = getpass.getpass("enter password: ")
  3. print pwd
Reputation Points: 75
Solved Threads: 44
Junior Poster
ghostdog74 is offline Offline
156 posts
since Apr 2006
Mar 21st, 2007
0

Re: Masking a string input

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

show='*'
Reputation Points: 92
Solved Threads: 156
Practically a Master Poster
jrcagle is offline Offline
608 posts
since Jul 2006
Mar 22nd, 2007
0

Re: Masking a string input

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Gumster is offline Offline
6 posts
since Mar 2007
Mar 23rd, 2007
0

Re: Masking a string input

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
Reputation Points: 92
Solved Threads: 156
Practically a Master Poster
jrcagle is offline Offline
608 posts
since Jul 2006
Mar 24th, 2007
0

Re: Masking a string input

maybe you can try this . Not tested
Python Syntax (Toggle Plain Text)
  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.
Reputation Points: 75
Solved Threads: 44
Junior Poster
ghostdog74 is offline Offline
156 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Wrapping text in the IDE
Next Thread in Python Forum Timeline: From phrase image





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC