GameNaps
GameNaps

Reputation: 13

What is the best way to convert input to * while typing in python?

So I am a total beginner to both programming and python and learned about input recently so I wrote a short and basic sort of login/registration script that doesn't actually do anything just something I did for fun. This is the full code.

    confirm = getpass.getpass()
    user=input("Choose your username:")
    password=input("Choose your password:")
    confirm=input("Confirm your password:")
    if(password==confirm):
        print("Password matches")
        emal=input("Enter your email:")
        print("Thank you for registering")
        close=input("Press Enter to close the prompt")
    while(password!=confirm):
        print("Password does not match")
        close2=input("Press Enter to try confirming the password again")
        password=input("Choose your password:")
        confirm=input("Confirm your password:")

So basically I just wanted to make it a bit cooler so I was wondering how I can make the input that I put in both password and confirm convert to * while I type it. Would it be best to just rewrite the code for password and confirm inputs or can I just upgrade the original code for them somehow. I tried getpass, but since i'm such a beginner I would need some help to work with that and see if I can even use it for the confirm as well.

Upvotes: 1

Views: 63

Answers (1)

Joran Beasley
Joran Beasley

Reputation: 113978

import getpass
password=getpass.getpass("Choose your password:")

will not print your output to terminal (it doesnt give you stars but meh)

Upvotes: 1

Related Questions