disguise letters in password

javajom

Javajon
Local time
Today, 07:16
Joined
Mar 5, 2008
Messages
37
Hi,
I've had a long look around this forum and others and had no luck finding any help. What I need is a function to change the letters on the password input so that instead of the word typed by the user, there would be a line of dots or something to disguise the word. Has anybody done something like this in VB and if so how?
 
What version of MS Access are you using?
Im using 2007 (so might not be in prior versions).
I know this isn't VBA but it should still work :)
If you select your textbox and then go to the properties in the Data tab there should be something called Input Mask click the '...' button at the end of the line and then you can select 'Password' as the Input Mask.
You can still find out what the user typed just as you would normally :)

Hope that this helps :)
 
Disguise letters in password

Hi, thanks but it's all in code. I have a spreadsheet which contains names, username and securit level, which is exported to a table called secure111 and from there the information goes int five arrays each will have a different security level allowing the user to do or not do things on the form according to there level.

So the code part:
pWord = InputBox("Please enter password", "JMJJ OFFICE SOLUTIONS", "User Verification")
is the bit I need to work on, any ideas???


PHP:
Public Function protect()

Dim cnn1 As adodb.Connection
Set cnn1 = CurrentProject.Connection

Dim myRecordSet As New adodb.Recordset
myRecordSet.ActiveConnection = cnn1
Dim data5(10) As String
Dim data4(10) As String
Dim data3(10) As String
Dim data2(10) As String
Dim data1(10) As String

Dim data5a(10) As String
Dim data4a(10) As String
Dim data3a(10) As String
Dim data2a(10) As String
Dim data1a(10) As String

Dim pWord As String
Dim hello As String
Dim retry As String

Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim m As Integer

Dim count1 As Integer
Dim count2 As Integer
Dim count3 As Integer
Dim count4 As Integer
Dim count5 As Integer

Dim ans As Boolean
Dim ans1 As Boolean
Dim ans2 As Boolean

ans = False
ans1 = False
ans2 = False

count1 = 0
count2 = 0
count3 = 0
count4 = 0
count5 = 0

i = 0
j = 0
k = 0
l = 0
m = 0

Dim mySQL As String
mySQL = " SELECT Username, securityLevel, FirstName, Surname"
mySQL = mySQL + " from secure111"
mySQL = mySQL + " WHERE(((secure111.securityLevel) >=0))"

myRecordSet.Open mySQL
While myRecordSet.EOF = False
If myRecordSet.Fields(1).Value = 5 Then
data5(i) = (myRecordSet.Fields(0).Value)
data5a(i) = ((myRecordSet.Fields(2).Value) + " " + (myRecordSet.Fields(3).Value))
i = i + 1
End If
If myRecordSet.Fields(1).Value = 4 Then
data4(j) = (myRecordSet.Fields(0).Value)
data4a(j) = ((myRecordSet.Fields(2).Value) + " " + (myRecordSet.Fields(3).Value))
j = j + 1
End If
If myRecordSet.Fields(1).Value = 3 Then
data3(k) = (myRecordSet.Fields(0).Value)
data3a(k) = ((myRecordSet.Fields(2).Value) + " " + (myRecordSet.Fields(3).Value))
k = k + 1
End If
If myRecordSet.Fields(1).Value = 2 Then
data2(l) = (myRecordSet.Fields(0).Value)
data2a(l) = ((myRecordSet.Fields(2).Value) + " " + (myRecordSet.Fields(3).Value))
l = l + 1
End If
If myRecordSet.Fields(1).Value = 1 Then
data1(m) = (myRecordSet.Fields(0).Value)
data1a(m) = ((myRecordSet.Fields(2).Value) + " " + (myRecordSet.Fields(3).Value))
m = m + 1
End If
myRecordSet.MoveNext
Wend
myRecordSet.Close
Set myRecordSet = Nothing
Set cnn1 = Nothing


pWord = InputBox("Please enter password", "JMJJ OFFICE SOLUTIONS", "User Verification")
If pWord = "" Then
Application.Quit
End If

Do While (count5 <= 10)
If pWord = (data5(count5)) Then
hello = MsgBox("Hello Administator " + data5a(count5), vbYes, "JMJJ OFFICE SOLUTIONS")
ans = True
DoCmd.OpenForm ("stock"), acWindowNormal
Forms!stock.UseForJobNumber.Enabled = True
Forms!stock.HowManyInStock.Enabled = True
Forms!stock.PartDesc.Enabled = True
Forms!stock.Partno.Enabled = True
End If
count5 = count5 + 1
Loop


Do While (count4 <= 10)
If pWord = (data4(count4)) Then
hello = MsgBox("Hello User " + data4a(count4), vbYes, "JMJJ OFFICE SOLUTIONS")
ans = True
ans1 = True
DoCmd.OpenForm ("stock"), acWindowNormal
Forms!stock.UseForJobNumber.Locked = True
End If
count4 = count4 + 1
Loop


Do While (count3 <= 10)
If pWord = (data3(count3)) Then
hello = MsgBox("Hello Scheduler " + data3a(count3), vbYes, "JMJJ OFFICE SOLUTIONS")
ans = True
ans2 = True
DoCmd.OpenForm ("stock"), acWindowNormal
Forms!stock.UseForJobNumber.SetFocus
Forms!stock.HowManyInStock.Locked = True
Forms!stock.PartDesc.Enabled = False
Forms!stock.Partno.Enabled = False
End If
count3 = count3 + 1
Loop

Do While (count2 <= 10)
If pWord = (data2(count2)) Then
hello = MsgBox("Hello Scheduler " + data2a(count2), vbYes, "JMJJ OFFICE SOLUTIONS")
ans = True
ans2 = True
DoCmd.OpenForm ("stock"), acWindowNormal
Forms!stock.UseForJobNumber.SetFocus
Forms!stock.HowManyInStock.Locked = True
Forms!stock.PartDesc.Enabled = False
Forms!stock.Partno.Enabled = False
End If
count2 = count2 + 1
Loop

Do While (count1 <= 10)
If pWord = (data1(count1)) Then
hello = MsgBox("Hello Scheduler " + data1a(count1), vbYes, "JMJJ OFFICE SOLUTIONS")
ans = True
ans2 = True
DoCmd.OpenForm ("stock"), acWindowNormal
Forms!stock.UseForJobNumber.SetFocus
Forms!stock.HowManyInStock.Locked = True
Forms!stock.PartDesc.Enabled = False
Forms!stock.Partno.Enabled = False
End If
count1 = count1 + 1
Loop

If ans = False Then
MsgBox ("Sorry need password")
End If
End Function
 
Last edited:
you have to write your own inputbox procedure, and in that you can mask the password with hidden characters. Its not hard - just a simple form will do
 
Hi,
Had a go at the password form and having problems. I made a form called secure111 from a table named the same which is imported from a Excell sreadsheet and put a text box in it and made it password on the input mask. Then in the main function altered
pWord = InputBox("Please enter password", "JMJJ OFFICE SOLUTIONS", "User Verification")
to
pWord = Forms!secure111.ques.Value thinking that
dim pWord as string would now have the value of Forms!secure111.ques (ques is the label box in the form) ie the password the user entered, so how do you make pWord the value of the string that has been enterd by the user???
 
Re: Dk

Why not use the InputBoxDK module?

Code:
Option Compare Database

Option Explicit
'////////////////////////////////////////////////////////////////////
'Password masked inputbox
'Allows you to hide characters entered in a VBA Inputbox.
'
'Code written by Daniel Klann
'March 2003
'////////////////////////////////////////////////////////////////////
Public blnUnlocked As Boolean

'API functions to be used
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, _
                                                      ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long

Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long

Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" _
                                          (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, _
                                          ByVal dwThreadId As Long) As Long

Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long

Private Declare Function SendDlgItemMessage Lib "user32" Alias "SendDlgItemMessageA" _
                                            (ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal wMsg As Long, _
                                            ByVal wParam As Long, ByVal lParam As Long) As Long

Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, _
                                                                          ByVal lpClassName As String, _
                                                                          ByVal nMaxCount As Long) As Long

Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long

'Constants to be used in our API functions
Private Const EM_SETPASSWORDCHAR = &HCC
Private Const WH_CBT = 5
Private Const HCBT_ACTIVATE = 5
Private Const HC_ACTION = 0

Private hHook As Long

Public Function NewProc(ByVal lngCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim RetVal
    Dim strClassName As String, lngBuffer As Long

    If lngCode < HC_ACTION Then
        NewProc = CallNextHookEx(hHook, lngCode, wParam, lParam)
        Exit Function
    End If

    strClassName = String$(256, " ")
    lngBuffer = 255

    If lngCode = HCBT_ACTIVATE Then    'A window has been activated

        RetVal = GetClassName(wParam, strClassName, lngBuffer)

        If Left$(strClassName, RetVal) = "#32770" Then  'Class name of the Inputbox

            'This changes the edit control so that it display the password character *.
            'You can change the Asc("*") as you please.
            SendDlgItemMessage wParam, &H1324, EM_SETPASSWORDCHAR, Asc("*"), &H0
        End If

    End If

    'This line will ensure that any other hooks that may be in place are
    'called correctly.
    CallNextHookEx hHook, lngCode, wParam, lParam

End Function

Public Function InputBoxDK(Prompt, Optional Title, Optional Default, Optional XPos, _
                        Optional YPos, Optional HelpFile, Optional Context) As String
    Dim lngModHwnd As Long, lngThreadID As Long

    lngThreadID = GetCurrentThreadId
    lngModHwnd = GetModuleHandle(vbNullString)

    hHook = SetWindowsHookEx(WH_CBT, AddressOf NewProc, lngModHwnd, lngThreadID)

    InputBoxDK = InputBox(Prompt, Title, Default, XPos, YPos, HelpFile, Context)
    UnhookWindowsHookEx hHook

End Function
 

Users who are viewing this thread

Back
Top Bottom