Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password encrypt message box 1

Status
Not open for further replies.

icewiper

Technical User
Apr 8, 2005
30
US
might might seem like an odd question but what I would like is to have the password encrypted. Example "******" as the person types it in the message box, instead of showing the actual passwoed.
I am using the code below

Dim PassWord As String

PassWord = InputBox("Enter Password")
If PassWord = "Password" Then
DoCmd.OpenForm "CHANGEAmountandNumofEmp"
Else
MsgBox ("You're not authorized so don't click here")
End If

i have searched all through tek-tips but haven't found anything that could help me.

Thanks in advance
 
I do not think you can do this with InputBox, but you could create a small form and use that.
 
Hot topic see thread702-1191871. My suggestion is the same as Remou's
 
I have some code that I will post that I use on input boxes. If you cant wait you can search the web, that is probably where I found it. You are going to have to make some use of windows api calls to accomplish this. I will try and post this later today if I can dig it up.



Andy Baldwin

"Testing is the most overlooked programming language on the books!
 
Some functions you will need to declare.

' API set A:
' Used by the callback process (TimerProc) to hook into
' the InputBox window
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
' Constants for API set A

Const EM_SETPASSWORDCHAR = &HCC

Public Const NV_INPUTBOX As Long = &H5000&



Public Function TimerProc(ByVal lHwnd&, ByVal uMsg&, _
ByVal lIDEvent&, ByVal lDWTime&) As Long
' This function allows for a mask character on an inputbox
' Usage (Replace anything between [] with valid names from your project):
' From a form or module:
' 1. Declare a Long variable
' 2. Call the timer function: [variable] = SetTimer([form].Hwnd, NV_INPUTBOX, [elapsed time], AddressOf [function name])
' 2b. Example usage from a form: lTemp = SetTimer(Me.Hwnd, NV_INPUTBOX, 1, AddressOf TimerProc)
' 3. Create your InputBox as usual
Dim lEditHwnd As Long ' Find a handle to the InputBox window, then to the textbox ' the user types in (Known as "Edit") ' ' **This part is VERY important, here is how the FindWindowEx call should look: ' **Only change the parameters that are enclosed in [ ] in the following example ' ' [variable] = FindWindowEx(FindWindow("#32770", "[caption of your InputBox]"), 0, "Edit", "") '
lEditHwnd = FindWindowEx(FindWindow("#32770", "Password Please"), 0, "Edit", "")
' Send the mask character to the target InputBox when the user types
' The mask character in this sample is the Asc("*") - the "*" can be changed
' to whatever you like.
Call SendMessage(lEditHwnd, EM_SETPASSWORDCHAR, Asc("*"), 0)
' Destroy the timer object when done (The user clicks OK or Cancel from the InputBox)
KillTimer lHwnd, lIDEvent
End Function


'Sample of retrieving a simple text field from a db that is the password required and comparing it to the input box item

Private Sub Command3_Click()

On Error GoTo Err_Out
Dim lTemp As Long
Dim sTemp As String

ConnectData
stsql = "SELECT * from pw"
rsData.Open stsql, conDb, adOpenStatic, adLockOptimistic

If rsData.RecordCount <> 1 Then
Beep
MsgBox "Database error. Please contact IT.", vbOKOnly + vbCritical, "Error"
Exit Sub
End
End If

stPass = rsData![pw]

lTemp = SetTimer(Me.hwnd, NV_INPUTBOX, 1, AddressOf TimerProc)
sTemp = InputBox("Please Enter your password", "Password Please")
If sTemp = vbNullString Then ' If the user clicked OK without entering anything
' Or if the user clicked cancel, generate a custom error
Err.Raise 1000, "Password Entry", "A Password is required"
Else
If sTemp = stPass Then
Screen.MousePointer = 11
frmMaint.Show vbModal
Else
MsgBox "You did not enter the correct password."
End If

End If
Exit Sub
Err_Out:
Select Case Err.Number
Case 1000
MsgBox Err.Description, vbCritical + vbOKOnly, Err.Source
Err.Clear

Case Else
Err.Clear
Unload Me
End Select

End Sub


Try this on for size.

Andy Baldwin

"Testing is the most overlooked programming language on the books!
 
I thank you guys for all your help ..... abaldwin I will try that out. Again thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top