locked
Hidden Password Input for GraphicsWindow. RRS feed

  • General discussion

  • Hello all~

    Remember a while back when I was working on the faux login program using TextWindow? I needed a set-up for it to hide the password -to make it look a little more authentic- and GoToLoop sent me lines of code that were involved in the hiding of characters.

    Now, I am using LitDev's extension and incorporating LDEmail so I can have an email client that sends email messages. During the login process -which is legitimate this time- I want the password to be hidden. I am trying to alter GoToLoop's code to work with the TextBox elements.

    I set this up as a discussion so I can try and keep track of what I am doing as well as keep it a place where I can ask for help with certain pieces of code (as I am still new to GraphicsWindow setups.)

    Here is what I got from GoToLoop:

    '==============================================================='
    ' Hidden CLI Password Input by GoToLoop in March 2012 '
    '==============================================================='
    
    Sub HiddenCLIInput
      '--- Accepts an input from the user w/o displaying what is being typed
      '--- Returns HIPWStr as the string typed
      '--- Accepts HIPWMax as maximum # of chars which HIPWStr can have
      
      SpecialCharsHeader()
      HiddenInputInit()
      HiddenInputLoop()
      
    EndSub
    '------------------------------------------------------------------------------------------------------------'
    Sub HiddenInputInit
      
      InitCursorX = TextWindow.CursorLeft
      InitCursorY = TextWindow.CursorTop
      
      If HIPWMax <= 0 Then    ' Max # of chars which can be accepted from user
        HIPWMax = 255         ' If HIPWMax is undetermined, use default 255
      EndIf
      
      HIPWKey     = ""    ' Typed char to be analysed
      HIPWStr     = ""    ' Password result formed outta accepted HIPWKey chars
      HiddenChars = ""    ' Which HIPWStrDisplay derives from
      HiddenChar  = STAR  ' Char displayed in place of what is being typed
      EnterKey    = CR    ' Key to confirm the input
      DeleteKey   = BS    ' Key to delete last char stored in HIPWStr
      
      For num = 1 To HIPWMax
        HiddenChars = HiddenChars + HiddenChar
      EndFor
      
    EndSub
    '------------------------------------------------------------------------------------------------------------'
    Sub HiddenInputLoop
      
      While HIPWKey <> EnterKey
        HIPWKey = TextWindow.ReadKey()   ' Waits next key to be hit
        HiddenInputParse()    ' Decides if it can be accept
        HiddenInputHide()     ' Replaces typed by HiddenChars
      EndWhile
      
    EndSub
    '------------------------------------------------------------------------------------------------------------'
    Sub HiddenInputParse
      
      HIPWKeyCode = Text.GetCharacterCode(HIPWKey)
      If HIPWKeyCode >= 32 Then                     ' Tests if printable
        HIPWStr   = Text.Append(HIPWStr  HIPWKey)   ' Creates PW string
      EndIf
      
      HIPWStrLen = Text.GetLength(HIPWStr) 
      If HIPWStrLen > HIPWMax Then          ' Checks if size passed limit
        HIPWKey  = DeleteKey
      EndIf
      
      If HIPWKey = DeleteKey Then   ' Deletes last char typed
        TextWindow.Write(SPC + BS + BS + SPC + BS + BEL)
        HIPWStr  = Text.GetSubText(HIPWStr  1  HIPWStrLen-1)
      EndIf
      
    EndSub
    '------------------------------------------------------------------------------------------------------------'
    Sub HiddenInputHide
      
      HIPWStrLen = Text.GetLength(HIPWStr)
      HIPWStrDisplay = Text.GetSubText(HiddenChars  1  HIPWStrLen)
      
      TextWindow.CursorLeft = InitCursorX   ' Repositions cursor at the beginning
      TextWindow.CursorTop  = InitCursorY
      TextWindow.Write(HIPWStrDisplay)      ' to display HiddenChars
      
    EndSub
    '------------------------------------------------------------------------------------------------------------'
    
    '==============================================================='
    ' Constant Header Includes '
    '==============================================================='
    
    Sub SpecialCharsHeader
      ' --- Initializes constants for special control characters in ASCII code:
      
      BEL= Text.GetCharacter   ( 7)   ' Makes internal PC-Speaker buzz
      BS=  Text.GetCharacter   ( 8)   ' Backspace
      TAB= Text.GetCharacter   ( 9)   ' Horizontal Tabulation (HT)
      LF=  Text.GetCharacter   (10)   ' Line-Feed (jumps a line)
      CR=  Text.GetCharacter   (13)   ' Carriage Return
      ESC= Text.GetCharacter   (27)   ' Escape Key
      CRS= Text.GetCharacter   (22)   ' Cursor
      ARW= Text.GetCharacter   (26)   ' Right Arrow
      QUO= Text.GetCharacter   (34)   ' Double Quotation Mark
      SQU= Text.GetCharacter  (166)   ' Half Vertical Rectangle
      APO=                     "'"    ' Apostrophe
      DOT=                     "."    ' Period
      COMMA=                   ","    ' Comma
      STAR=                    "*"    ' Asterisk
      SPC=                     " "    ' SPaCe
      
    EndSub
    '------------------------------------------------------------------------------------------------------------'

    That is what I will be altering, so wish me luck!

    Thanks again GoToLoop for providing this code to me for my faux login program! And thank you for commenting everything so I can follow along :P

    -JOman Mied


    I can write 1000 lines of code in roughly 10 seconds. Here's how:
    i = 1

    For i = 1 to 1000
    TextWindow.WriteLine(i+ ". Code")
    Program.Delay(10)
    EndFor

    Make Sense?

    Wednesday, August 7, 2013 8:05 PM

All replies

  • @ that post: is-it-possible-to-show-userinput-as-dots

    My 1st example was for TextWindow. However, @ my 2nd 1, I've re-factored that to work for GraphicsWindow too!

    CLI version: TGH751

    GUI version: THP414-1


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Wednesday, August 7, 2013 9:58 PM
    Answerer
  • Thank you GoToLoop! I re-formatted the GraphicsWindows version so it wouldn't come up with it's own GUI. It works well!
    And I found out that to get the original text, I need to use the variable "PWStr" as the password. 

    Thanks again!


    I can write 1000 lines of code in roughly 10 seconds. Here's how:
    i = 1

    For i = 1 to 1000
    TextWindow.WriteLine(i+ ". Code")
    Program.Delay(10)
    EndFor

    Make Sense?

    Friday, August 9, 2013 3:14 AM