0

i am creating this basic login system and i want to replace the characters of the password as the user enters them and not display the password as the user enters it instead display the # symbol


def login() :
    l_user = input('Username: ')
    l_pass= input("password")
    with open('username.txt', mode='r')as user_file:
            validate_u = user_file.readlines()
    with open('password.txt', mode='r')as pass_file:
        validate_p = pass_file.readlines()
    if l_user + "\n" in validate_u:  # ReadLines() adds newlines
        user_num = validate_u.index(l_user + "\n")
        if l_pass + "\n" == validate_p[user_num]:
            print("Password correct!")
        else:
            print("Password incorrect!")
    else:
        print("Cannot find your username!")
Dexter
  • 13
  • 7
  • Does this answer your question? [Masking user input in python with asterisks](https://stackoverflow.com/questions/27631629/masking-user-input-in-python-with-asterisks) – 777moneymaker Jul 29 '20 at 15:51
  • no it doesn't because in python 3 input is used instead of raw input – Dexter Jul 30 '20 at 03:20
  • 1
    Check this out then: https://stackoverflow.com/a/54603772/5362583 – Alok Jul 30 '20 at 09:07

1 Answers1

0

Here you go:

>>> from getpass import getpass
>>> p = getpass(prompt='Enter your password:')
Enter your password:
>>> p
'pswrd'
777moneymaker
  • 622
  • 4
  • 14
  • but i want to mask the password like as user times it it prints '*' on screen instead of typed password – Dexter Jul 30 '20 at 11:40