Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: VB5,VB6
Expertise: Advanced
Mar 11, 2000



Application Security Testing: An Integral Part of DevOps

Implement password-protected TextBox that are really secure

As explained in another tip in this TipBank, users can peek at the contents of password-protected TextBox controls with a simple Spy-like program, or even with a VB program plus some API functions. The problem is that such TextBox controls react to the WM_GETTEXT message and the GetWindowText API function as if they were regular TextBox controls. This holds True under Windows 95, 98 and NT. (Windows 2000 has fixed this security issue.)

If you want to make sure that no one can steal passwords from your VB programs, you only have to subclass the WM_GETTEXT message and discard the call. The following code snippet relies on the MsgHook.Dll (that you can download from the FileBank section of this site).

Dim WithEvents TextHook As MsgHook

Private Sub Form_Load()
    Set TextHook = New MsgHook
    ' Text1 is the password-protected control
    TextHook.StartSubclass Text1
End Sub

Private Sub TextHook_BeforeMessage(uMsg As Long, wParam As Long, lParam As Long, _
    retValue As Long, Cancel As Boolean)
    ' filter out the WM_GETTEXT message    
    If uMsg = WM_GETTEXT Then Cancel = True
End Sub

If you discard the WM_GETTEXT message, no application will be able to read the contents of your control.

It is remarkable that this subclassing code doesn't prevent the current application from reading the contents of the password-protected control. The reason is - evidently - that VB doesn't rely on API calls to read the Text property of a TextBox.

Francesco Balena
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date