Quantcast

Jump to content


Photo

Print asterisk instead of password


  • Please log in to reply
9 replies to this topic

#1 nino

nino
  • 9 posts

Posted 02 May 2012 - 06:29 AM

How can I input a code into Python that will output the typed characters as asterisks.

So when it goes:

password = raw_input("Enter Password: ")
When they enter their password Python will recognise the characters but show an asterisk for each character on the screen instead of the actual password. For security reasons obviously.

Any help?

#2 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 02 May 2012 - 06:32 AM

import getpass

password = getpass.getpass()

It won't display asterisks but it also won't show what they typed.

#3 shrouded

shrouded
  • lil'cluck

  • 1250 posts


Users Awards

Posted 02 May 2012 - 06:35 AM

http://www.daniweb.c...e-screen-output

This should help you out. The first section of code is the one you want.

#4 Irradium

Irradium
  • Pyro (699) Maniac

  • 892 posts


Users Awards

Posted 02 May 2012 - 07:12 AM

import getpass

password = getpass.getpass()

It won't display asterisks but it also won't show what they typed.


I never knew that Python had a standard library that could do this! It's not my thread, but cheers for that Waser! :)

#5 nino

nino
  • 9 posts

Posted 03 May 2012 - 03:37 AM

None of these solutions seem to be working for me :(

#6 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 03 May 2012 - 03:39 AM

None of these solutions seem to be working for me :(


The one I posted definitely works so you're doing something wrong.

#7 nino

nino
  • 9 posts

Posted 03 May 2012 - 03:42 AM

The one I posted definitely works so you're doing something wrong.


I used it but it still shows the characters I type. Is it because I'm on Python 2.6?

#8 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 03 May 2012 - 03:55 AM

I used it but it still shows the characters I type. Is it because I'm on Python 2.6?


It's possible that there's some difference in 2.6 because I use 2.7 and it works fine in that.

#9 shrouded

shrouded
  • lil'cluck

  • 1250 posts


Users Awards

Posted 03 May 2012 - 06:31 AM

It's possible that there's some difference in 2.6 because I use 2.7 and it works fine in that.


I also use 2.7

#10 Irradium

Irradium
  • Pyro (699) Maniac

  • 892 posts


Users Awards

Posted 03 May 2012 - 08:39 AM

Yes, I tried integrating it into a program of mine and seems to work quite well, and I use 2.7.3.

A stack trace (the lines of red writing in an IDE when the program stops) or the line of code where it's implemented may be a good idea to post here?


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users