5

How to get asterisks during inputting password using getpass module in python?

actual Results:

import getpass                                                                       

p=getpass.getpass("Enter the Password:")

Enter the Password:

print (p)

Output: password

Expecting results:

import getpass                                                                       

p=getpass.getpass("Enter the Password:")

Enter the Password:********

print (p)

Output: password

Python Version: 2.7

preethy tulpi
  • 415
  • 1
  • 5
  • 15
  • 5
    `getpass` doesn't have that functionality. You don't get stars, you just get an un-echoed password, if the terminal can do that. FWIW, printing stars is less secure, because it lets an onlooker know how long the password is. – PM 2Ring Feb 12 '18 at 11:36
  • 1
    It does have the functionality but does so only when echo free input is unavailable and when it does, it prints a warning message to stream. [source](https://docs.python.org/3.1/library/getpass.html) – abybaddi009 Feb 12 '18 at 11:40
  • This question was answered already here: https://stackoverflow.com/questions/35805078/how-do-i-convert-a-password-into-asterisks-while-it-is-being-entered/52636454#52636454 – Tigran Aivazian Oct 04 '18 at 16:37
  • 1
    @TigranAivazian The accepted answer of the linked question hides the input completely, rather than display stars. – Stevoisiak Apr 03 '19 at 20:16
  • You can find answer for this here: https://stackoverflow.com/questions/35805078/how-do-i-convert-a-password-into-asterisks-while-it-is-being-entered/35805111 – anon Mar 15 '20 at 12:46
  • Concealing password length from shoulder-surfers is a very minor security benefit, while not acknowledging input with anything is a large usability cost. – Reid Jul 22 '21 at 20:22

0 Answers0