none
Password Protection RRS feed

  • Question

  • Hi everyone,

    I created a login using a textbox and button, when I type a password into the textbox how can I make it so it doesn't display the actually password but * for each character instead, or is there anyother way to hide this.

    Kirk.

    Wednesday, November 24, 2010 10:02 PM

Answers

  • Tricky one Kirk,

    This is the best approach I can see - it works OK apart from the fact that the textbox caret seems to be at the start of the input as you type due to the SetTextBoxText command - if you ignore this and don't reposition the caret by clicking inside the textbox it works.

    textbox1 = Controls.AddTextBox(50,50)
    button1 = Controls.AddButton("Password Entered",50,100)
    textbox2 = Controls.AddTextBox(50,150)
    Controls.TextTyped = OnTextTyped
    Controls.ButtonClicked = OnButtonClicked
    password = ""

    Sub OnTextTyped
      If (Controls.LastTypedTextBox = textbox1) Then
        txt = Controls.GetTextBoxText(textbox1)
        lastchar = Text.GetSubText(txt,1,1) 'the first character is always the last entered due to the caret positioning commented below
        If (lastchar <> "*") Then ' only handle non * character - see comment below
          password = password + lastchar
          len = Text.GetLength(Controls.GetTextBoxText(textbox1))
          txt = ""
          For i = 1 To len
            txt = txt+"*"
          EndFor
          Controls.SetTextBoxText(textbox1,txt) 'This calls the OnTyextTyped event and set the caret at the start of the text which we cannot change I think
        EndIf
      EndIf
    EndSub

    Sub OnButtonClicked
      Controls.SetTextBoxText(textbox2,password)
      password = ""
      Controls.SetTextBoxText(textbox1,"")
    EndSub

    • Marked as answer by Kirkkaf Thursday, November 25, 2010 9:35 PM
    Wednesday, November 24, 2010 11:13 PM
    Moderator

All replies

  • Tricky one Kirk,

    This is the best approach I can see - it works OK apart from the fact that the textbox caret seems to be at the start of the input as you type due to the SetTextBoxText command - if you ignore this and don't reposition the caret by clicking inside the textbox it works.

    textbox1 = Controls.AddTextBox(50,50)
    button1 = Controls.AddButton("Password Entered",50,100)
    textbox2 = Controls.AddTextBox(50,150)
    Controls.TextTyped = OnTextTyped
    Controls.ButtonClicked = OnButtonClicked
    password = ""

    Sub OnTextTyped
      If (Controls.LastTypedTextBox = textbox1) Then
        txt = Controls.GetTextBoxText(textbox1)
        lastchar = Text.GetSubText(txt,1,1) 'the first character is always the last entered due to the caret positioning commented below
        If (lastchar <> "*") Then ' only handle non * character - see comment below
          password = password + lastchar
          len = Text.GetLength(Controls.GetTextBoxText(textbox1))
          txt = ""
          For i = 1 To len
            txt = txt+"*"
          EndFor
          Controls.SetTextBoxText(textbox1,txt) 'This calls the OnTyextTyped event and set the caret at the start of the text which we cannot change I think
        EndIf
      EndIf
    EndSub

    Sub OnButtonClicked
      Controls.SetTextBoxText(textbox2,password)
      password = ""
      Controls.SetTextBoxText(textbox1,"")
    EndSub

    • Marked as answer by Kirkkaf Thursday, November 25, 2010 9:35 PM
    Wednesday, November 24, 2010 11:13 PM
    Moderator
  • There is a control for password boxes under the data extension

    GameWindow.ReplaceGraphicsWindow()

    GameControls2D.AddPasswordBox("", 0, 0, 100, 25)


    ~~AirWaves!!~~
    Wednesday, November 24, 2010 11:44 PM
  • Hi litdev & AirWaves,

    Thanks for both your replys I have gone along with litdevs idea as I am trying to stick to the standard small basic lib and not use any extensions.

    However thanks for the nice simple answer AirWaves.

    Kirk.

    Thursday, November 25, 2010 9:34 PM