by Wade Reynolds (3 Submissions)
Category: String Manipulation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Wed 16th February 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Simple secure password textbox example. Use a locked Textbox control as a password Textbox that seems to accept typed user input without
'
' Code by Wade Reynolds, 2000
'
' "Password Textbox That Does Not Store The Password"
'
' Create a new project with a form,
' textbox (Text1), and a label (Label1).
'
' (Label1 exists only to show you what is in strPassword.)
'
' Copy and paste the following code into Form1's
' code window.
'
' Enjoy!
'
Dim strPassword As String 'Stores the password typed into the locked textbox
Private Sub Form_Load()
Text1.Locked = True 'The control is locked, but we can still set focus and 'type' into it.
Text1.PasswordChar = "*" 'Sets the textbox as a password box using * as the mask character
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case Is = vbKeyBack
If Text1.Text = "" Then 'If nothing in Text1 (or in strPassword), ignore the backspace subroutine
Else
strPassword = Left(strPassword, (Len(strPassword) - 1)) 'Erase the last character from strPassword
Text1.Text = Left(Text1.Text, (Len(Text1.Text) - 1)) 'Erase the last 'character' from Text1
Label1.Caption = strPassword 'Update Label1
End If
Case 9 To 47, 112 To 127
Case Else
Text1.Text = Text1.Text & Text1.PasswordChar 'Add a 'character' into Text1.Text
strPassword = strPassword & Chr(KeyCode) 'Add the new character to strPassword
Label1.Caption = strPassword 'Update Label1
End Select
End Sub
No comments have been posted about Simple secure password textbox example. Use a locked Textbox control as a password Textbox that see. Why not be the first to post a comment about Simple secure password textbox example. Use a locked Textbox control as a password Textbox that see.