Masked Input() in Console

Just starting out? Need help? Post your questions and find answers here.
User avatar
Catdaddy
User
User
Posts: 30
Joined: Wed Mar 23, 2022 3:40 pm

Masked Input() in Console

Post 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?
User avatar
mk-soft
Always Here
Always Here
Posts: 6209
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Masked Input() in Console

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Catdaddy
User
User
Posts: 30
Joined: Wed Mar 23, 2022 3:40 pm

Re: Masked Input() in Console

Post by Catdaddy »

That is EXACTLY what I need. Perfect. Thank you so much, mk-soft.
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 457
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Masked Input() in Console

Post by Mindphazer »

Works fine on Windows
But not on MacOS : #BS$ does NOT erase character
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
Post Reply