1

I am trying to create a password protected server but, when I go in to type my password, the output doesn’t let me type in the password. All the other inputs work just getpass doesn’t let me type input. Please help

import smtplib, json_store_client, getpass, hashlib, datetime, sys
from termcolor import colored
from time import sleep, ctime 


with smtplib.SMTP('smtp.gmail.com',587) as smtp:
    smtp.ehlo() #starts email procedure
    smtp.starttls() #encrypts
    smtp.ehlo() #starts the email procedure again
    pw=getpass.getpass(colored("Enter password:\n","green"))
    global attemptpw
    attemptpw = 0
    try:
        smtp.login("********@gmail.com",pw)
        #**** is my email, I just don’t want to show it
        x=chat("[MOD] {} ".format(opt2),True
     except:
        print(colored("Invalid Admin password","red"))
        sleep(1)
      else:
        print("password entered:",pw)

for my code I am using:
repl.it

edit: My code is here: repl.it/codingandmemes

  • Does "Enter password:" gets printed? For most of the times using `getpass` will give you echo free prompt. – Foocli Nov 14 '19 at 19:36
  • @Foocli, “Enter password:” gets printed in green, yes. But I will try that –  Nov 14 '19 at 20:52
  • Just tested the code without the text in the parenthesis `get pass.getpass(colored(string, color))` and it did not work. –  Nov 14 '19 at 20:56
  • Voting to close as not reproducible: as noted, the text that is typed will be recorded. See https://stackoverflow.com/questions/9202224/getting-a-hidden-password-input for the general canonical on `getpass` and other approaches to hidden password input. See https://stackoverflow.com/questions/35805078 for some additional answers specific to making `*` symbols show up for the password. – Karl Knechtel Aug 03 '22 at 03:42

1 Answers1

0

Tested your original code in repl.it and it worked, just add print(pw) right after the line pw=getpass.getpass(colored("Enter password:\n","green")) to verify.

getpass implements the echo-free feature (doc here) which means whatever you type, it will not be printed on the screen, you might be expecting the little dots (••••••) to represent each character you type for password, echo-free means nothing at all, not even the little dots.

This is a feature widely implemented on unix systems to add a little extra security so that others won't be able to tell the length of your password, see this post.

Foocli
  • 157
  • 1
  • 11
  • Thanks, @Foocli, but is there a way to echo the password? Also, I am entering the correct password, and it does not accept it –  Nov 16 '19 at 13:22
  • I have another project that I want you to take a look at [(here)](https://repl.it/@CodingAndMemes/Loading-Repl) –  Nov 16 '19 at 13:45
  • As for your first question, `getpass` hide the password completely if the terminal supports that, if you want to print asterisks to let users know the length of their input, you might want to look into other libraries, for example [this post](https://stackoverflow.com/a/54603772/5302121) suggested [stdiomask](https://pypi.org/project/stdiomask/); or clearly if you want to directly print out the password, use `input`. – Foocli Nov 18 '19 at 14:46
  • @CodingAndMemes consider accepting the answer if I helped, and for your second question, start a new question and post your code directly in the question, I just checked and line 86 now is a simple print statement, I couldn't reproduce the error. You don't have to use so many external libs to implement your code, for example, [print in python can flush the output](https://stackoverflow.com/questions/230751/how-to-flush-output-of-print-function) and termcolor [last updated at Jan 2011](https://pypi.org/project/termcolor/)... that could be a problem if you run into problems. – Foocli Nov 18 '19 at 15:02