-1

I want to mask my keyboard input with a character such as an asterisk on Python version 3 and above on a windows operating system,

I have this so far,

import getpass

pswd = getpass.getpass('Password:')

I can hide the password input, but I am not able to display a character for each individual letter

I tried using msvcrt module, but an error saying no module name 'msvcrt' keeps popping up, probably because i have Python version 3 and above. I also don't want to use tKinter either.

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
  • 3
    You say "no one has been answering my question properly", but you only asked this question nine minutes ago. Your profile shows no other questions. Have a little patience. – Bryan Oakley Mar 01 '15 at 15:31
  • I another account, where I asked this question 2 days ago, everyone duplicated the question as, they misunderstood the question, just trying to clear things up – Abhinath Kumar Mar 01 '15 at 15:37
  • 1
    Asking another duplicate question isn't going to help you. This one will likely get closed as a duplicate too. See http://stackoverflow.com/help/reopen-questions for information about how to get your closed question re-opened. Edit the question to explain how the other question(s) didn't help and how this question is different. – Bryan Oakley Mar 01 '15 at 16:14
  • Thank you, Bryan, rephrased my question – Abhinath Kumar Mar 01 '15 at 16:24
  • Your edits haven't helped. Your question is absolutely a duplicate of your [earlier question](http://stackoverflow.com/questions/28791235/mask-input-with-character-python), and both are pretty much a duplicate of [this question](http://stackoverflow.com/questions/27631629/masking-user-input-in-python-with-asterisks) and possibly a few others. If you are asking specifically about using `getpass` you need to mention that, and if you're open to any solution you need to mention that, too. As it stands this is a very poorly worded question that isn't significantly different from similar questions. – Bryan Oakley Mar 01 '15 at 16:56
  • You know instead of ciritiziing the question, you could maybe help me and suggest a few solutions yourself, I am new to programming and stack overflow, so I may make mistakes, If you are not going to contribute please commenting furthur on this question – Abhinath Kumar Mar 02 '15 at 03:05
  • I would be willing to answer the question if I knew exactly what you were asking for. It is unclear how your question is any different from similar questions that already have answers. I'm merely trying to help you to write a question that will result in the best answers. – Bryan Oakley Mar 02 '15 at 11:54

1 Answers1

0

I think I have just what you need. Password is set to variable name 'psw'. This only seems to work in cmd though.

import msvcrt
import time
import sys
import os

def getPASS():
    print("Input password")
    list1 = []
    while True:
        char = msvcrt.getch()
        char =str(char)
        char = char[2:-1]
        if char == "\\n'" or char == "\\r":
            break
    elif char == "\\x08":
        del list1[-1]
        os.system("cls")
        print("Input password:")
        sys.stdout.write("*" * len(list1))
        sys.stdout.flush()
        continue
    else:
        list1.append(char)
        sys.stdout.write("*")
        sys.stdout.flush()
print("\n")
psw = "".join(list1)
print(psw)
invalid = ' ,:;/?"\}]{[-=+!@#$%^&*()|'
for x in psw:
    if x in invalid:
        print("Character %r is not allowed in password" % x)
        getPASS()
    else:
        pass

getPASS()

Please give any improvements, Dan

Dannydjrs
  • 33
  • 1
  • 5