Input mask for a password control - A2k

C

Chris Youlden

I have an unbound control on a form in which students enter their
college IDs. These IDs are 8 digit numbers.

Ideally this needs to be displayed as asterisks , but if 'Password' is
entered into the Input mask property, it seems that there is no way to
apply a standard mask to restrict characters to numeric only and only 8
in total.

Is there any other way to display asterisks when numerals are keyed in?

Any help appreciated.

Chris
 
A

aaron.kempf

Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function FindWindowEx Lib "user32" Alias
"FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1
As String, ByVal lpsz2 As String) As Long

Public Declare Function SetTimer& Lib "user32" (ByVal hwnd&, ByVal
nIDEvent&, ByVal uElapse&, ByVal lpTimerFunc&)
Private Declare Function KillTimer& Lib "user32" (ByVal hwnd&, ByVal
nIDEvent&)

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam
As Any) As Long

Const EM_SETPASSWORDCHAR = &HCC
Public Const NV_INPUTBOX As Long = &H5000&
Public WindowTitle As String

Public Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal
idEvent As Long, ByVal dwTime As Long)
Dim EditHwnd As Long
EditHwnd = FindWindowEx(FindWindow("#32770", WindowTitle), 0,
"Edit", "")

Call SendMessage(EditHwnd, EM_SETPASSWORDCHAR, Asc("*"), 0)
KillTimer hwnd, idEvent
End Sub

Public Function PasswordInputbox(Prompt As String, Title As String,
Optional Default As String, Optional XPos As Long, Optional YPos As
Long, Optional HelpFile As Long, Optional Context As Long) As String
Dim ret As String

SetTimer 0, 0, 1, AddressOf TimerProc
PasswordInputbox = InputBox(Prompt, Title, Default, XPos, YPos,
HelpFile, Context)
End Function

Public Function TestPassword()
On Error GoTo errhandler

Dim strPassword As String
strPassword = PasswordInputbox("Enter administrator password for access
to the ordermaster form", "ADMIN PASSWORD REQUIRED")

If strPassword <> "HELLO_WORLD" Then
MsgBox "Invalid Password.", vbOKOnly + vbCritical
Else
MsgBox "VALID Password.", vbOKOnly + vbCritical
End If

cleanexit:
Exit Function
errhandler:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbCritical
Resume Next
End Function
 
D

Douglas J. Steele

No, you can't do both.

You'll have to put code in the BeforeUpdate event to reject the input if
it's non-numeric.
 
L

Larry Daugherty

You're solving a non-problem. They're supposed to know their
"password". I hope you are also using some other user identifying
information. If it's just a single item entry of the password then it
should be pretty easy to hack. Also, If their IDs might be widely
known then their ID isn't a good password either.

HTH
 
C

Chris Youlden

Larry said:
You're solving a non-problem. They're supposed to know their
"password". I hope you are also using some other user identifying
information. If it's just a single item entry of the password then it
should be pretty easy to hack. Also, If their IDs might be widely
known then their ID isn't a good password either.

HTH

Thanks to everyone for your help. I will work on the BeforeUpdate event
as Douglas suggests.

I understand the point that Larry is making - but security is not the
essence here. The College ID system could not be called secure in any
way, they even use the 8 digit code before the '@' in the standard email
address for each student, so it's wide open.

My requirement is solely for the Student to be able to access various
data applicable to them.

Many thanks

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top