Page 1 of 1

Masked Input() in Console

Posted: Thu May 15, 2025 6:06 pm
by Catdaddy
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?

Re: Masked Input() in Console

Posted: Thu May 15, 2025 6:45 pm
by mk-soft
;)

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

Re: Masked Input() in Console

Posted: Thu May 15, 2025 7:32 pm
by Catdaddy
That is EXACTLY what I need. Perfect. Thank you so much, mk-soft.

Re: Masked Input() in Console

Posted: Fri May 16, 2025 11:20 am
by Mindphazer
Works fine on Windows
But not on MacOS : #BS$ does NOT erase character