Masked Input() in Console
Posted: Thu May 15, 2025 6:06 pm
Does anyone know of a way to mask an Input() response in the console? Like in a string or input requestor where you can designate a mask (like all "*") to conceal a password?
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
If OpenConsole()
Print("Password: ")
Repeat
KeyPressed$ = Inkey()
If KeyPressed$ <> ""
Select KeyPressed$
Case #LF$, #CR$
Break
Case #BS$
If Pass$
Pass$ = Left(Pass$, Len(Pass$) - 1)
Print(#BS$ + " " + #BS$)
EndIf
Default
If KeyPressed$ > " "
Pass$ + KeyPressed$
Print("*")
EndIf
EndSelect
Else
Delay(20) ; Don't eat all the CPU time, we're on a multitask OS
EndIf
ForEver
PrintN("")
PrintN("Show: " + Pass$)
Input()
EndIf