Skip to content
Sign upLog in
← Back to Community

How do you type letters and they appear as asterisks?

Profile icon
[deleted]

Python 3

Im trying to make a login page that automatically prints whatever is typed in asterisks.

Voters
Profile icon
DebbieZubi
Profile icon
NiaRubio
Profile icon
Kai_Justice
Comments
hotnewtop
Profile icon
Vandesm14

In HTML right? Use an input element: <input type="password">

Profile icon
iPenguin

Since you haven't given a programming language, the best universal method I can think of is to have a variable that stores what is typed and then print out an asterisk for however long the input is.

Profile icon
[deleted]

in python:

from prompt_toolkit import prompt prompt('enter in password: ', is_password=True)
Profile icon
[deleted]

@TaylorLiang
Thanks, if i wanted to make it so if the password is the one i have chosen, the program continues.

Profile icon
[deleted]

@AlexVasilkovsk1

do this. You will have to encrypt your password to a SHA256 hash though

import hashlib from prompt_toolkit import prompt def encrypt(text): sha_sig = \ hashlib.sha256(text.encode()).hexdigest() return sha_sig if encrypt(prompt('password: ', is_password=True)) == 'the sha256 hash': "do the thing you want to do"
Profile icon
[deleted]

@TaylorLiang
Ok I have done this, what is the variable for the password tho

Also pardon my lack of knowledge im new to coding.

Profile icon
[deleted]

@AlexVasilkovsk1
replace the sha256 hash with the hash for you password. use this website, and the output will be the sha256 hash

Profile icon
[deleted]

@TaylorLiang

from prompt_toolkit import prompt
import hashlib

def encrypt(text):
sha_sig =
hashlib.sha256(text.encode()).hexdigest()
return sha_sig

if encrypt(prompt('password: ', is_password=True)) == 'the sha256 hash':
"b3fa55f98fcfcaf6a15a7c4eb7cdd1b593693d3fef2fb7aec3b6768fd7c6a4ce"

print("hello")

Doesnt work?

the print("hello") is indented btw

Profile icon
[deleted]

@AlexVasilkovsk1
you misunderstood me.
replace your if statment with this:

if encrypt(prompt('password: ', is_password=True)) == 'b3fa55f98fcfcaf6a15a7c4eb7cdd1b593693d3fef2fb7aec3b6768fd7c6a4ce': print("Hello")

This is the corrected code

Profile icon
[deleted]

@TaylorLiang
Works great, ty for the help.