Results 1 to 24 of 24

Thread: *** mask password in inputbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2014
    Posts
    6

    *** mask password in inputbox

    Hello!

    I am trying to get this access code to work.
    It's for making **** in the field of an inputbox, so the password cant be seen.

    I's originally a code for a 32 bit system, so the real challenge here is converting it to 64 bit.

    The code are:

    Code:
    Public sPwd As String
    Public gMsgTitle As String
    Public gMsgType As String
    Public gMsgText As String
    Public gStatusText As String
    
    "FindWindowA" (ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long
    
    Private Declare PtrSafe Function FindWindowEx Lib "user32" Alias _
    "FindWindowExA" (ByVal hWnd1 As LongPtr, ByVal hWnd2 As LongPtr, _
    ByVal lpsz1 As String, ByVal lpsz2 As String) As LongPtr
    
    Public Declare PtrSafe Function SetTimer& Lib "user32" _
    (ByVal hwnd&, ByVal nIDEvent&, ByVal uElapse&, ByVal _
    lpTimerFunc&)
    
    Public Declare PtrSafe Function KillTimer& Lib "user32" _
    (ByVal hwnd&, ByVal nIDEvent&)
    
    Private Declare PtrSafe Function SendMessage Lib "user32" Alias _
    "SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As LongPtr, _
    ByVal wParam As LongPtr, lParam As Any) As LongPtr
    
    Const EM_SETPASSWORDCHAR = &HCC
    Public Const NV_INPUTBOX As Long = &H5000&
    And Function:

    Code:
    Public Function TimerProc(ByVal lHwnd&, ByVal uMsg&, _
    ByVal lIDEvent&, ByVal lDWTime&) As LongPtr
    
    Dim lTemp As Long
    Dim lEditHwnd As Long
    lTemp = FindWindowEx(FindWindow("#32770", "gMsgText"), 0, "Edit", "")
    lEditHwnd = FindWindowEx(FindWindow("#32770", "gMsgTitle"), 0, "Edit", "")
    
    Call SendMessage(lEditHwnd, EM_SETPASSWORDCHAR, Asc("*"), 0)
    
    KillTimer lHwnd, lIDEvent
    End Function
    Input box:

    Code:
    Private Sub OpnAdm_Click()
    
    gMsgTitle = "Begrenset Omrde"
    gMsgType = vbOKOnly + vbInformation
    gMsgText = "Tast inn passord"
      
    
    lTemp = SetTimer(Me.hwnd, NV_INPUTBOX, 1, AddressOf TimerProc)
    sPwd = InputBox(gMsgText, gMsgTitle)
    
    
    If strPasswd = "" Or strPasswd = Empty Then
    Exit Sub
    End If
    
    If strPasswd = "yslg53481" Then
    DoCmd.OpenForm "frmBatchReg"
    Else
    MsgBox "Beklager, du har ikke tilgang til denne delen av programmet", vbOKOnly, "Sikkerhetssjekk"
    Exit Sub
    End If
    
    
    End Sub
    Missing anything? The error I get is type missmatch on AddressOf TimerProc. But I know its also needs converting to 64 bit. Don't know how tough. Have 2013 access

    I know its 1000 times easier to just make a new form and pwd mask the inputmask, but this is not the case here. I rather have more code and less forms, and it get's on my nerves that I cant find it out, so just need see this through, especially when so many other 32 bit users got it to work

    Anyone know what to do here?

  2. #2
    Member pike's Avatar
    Join Date
    Jul 2008
    Location
    Alstonville, Australia
    Posts
    52

    Re: *** mask password in inputbox

    Kvracing

    try ..
    Code:
    Option Explicit
     
     '////////////////////////////////////////////////////////////////////
     'Password masked inputbox
     'Allows you to hide characters entered in a VBA Inputbox.
     '
     'Code written by Daniel Klann
     'http://www.danielklann.com/
     'March 2003
     
     '// Kindly permitted to be amended
     '// Amended by Ivan F Moala
     '// http://www.xcelfiles.com
     '// April 2003
     '// Works for Xl2000+ due the AddressOf Operator
     '////////////////////////////////////////////////////////////////////
     
     '********************   CALL FROM FORM *********************************
     '    Dim pwd As String
     '
     '    pwd = InputBoxDK("Please Enter Password Below!", "Database Administration Security Form.")
     '
     '    'If no password was entered.
     '    If pwd = "" Then
     '        MsgBox "You didn't enter a password!  You must enter password to 'enter the Administration Screen!" _
     '        , vbInformation, "Security Warning"
     '    End If
     '**************************************
     
     
     
     '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
     
     '// Make it public = avail to ALL Modules
     '// Lets simulate the VBA Input Function
    Public Function InputBoxDK(Prompt As String, Optional Title As String, _
        Optional Default As String, _
        Optional Xpos As Long, _
        Optional Ypos As Long, _
        Optional Helpfile As String, _
        Optional Context As Long) As String
         
        Dim lngModHwnd As Long, lngThreadID As Long
         
         '// Lets handle any Errors JIC! due to HookProc> App hang!
        On Error GoTo ExitProperly
        lngThreadID = GetCurrentThreadId
        lngModHwnd = GetModuleHandle(vbNullString)
         
        hHook = SetWindowsHookEx(WH_CBT, AddressOf NewProc, lngModHwnd, lngThreadID)
        If Xpos Then
            InputBoxDK = InputBox(Prompt, Title, Default, Xpos, Ypos, Helpfile, Context)
        Else
            InputBoxDK = InputBox(Prompt, Title, Default, , , Helpfile, Context)
        End If
         
    ExitProperly:
        UnhookWindowsHookEx hHook
         
    End Function
     
    Sub TestDKInputBox()
        Dim x
         
        x = InputBoxDK("Type your password here.", "Password Required")
        If x = "" Then End
        If x <> "1234" Then
            MsgBox "You didn't enter a correct password."
            End
        End If
         
        MsgBox "Welcome Creator!", vbExclamation
         
    End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2014
    Posts
    6

    Re: *** mask password in inputbox

    Quote Originally Posted by pike View Post
    Kvracing

    try ..
    Code:
    Option Explicit
     
     '////////////////////////////////////////////////////////////////////
     'Password masked inputbox
     'Allows you to hide characters entered in a VBA Inputbox.
     '
     'Code written by Daniel Klann
     'http://www.danielklann.com/
     'March 2003
     
     '// Kindly permitted to be amended
     '// Amended by Ivan F Moala
     '// http://www.xcelfiles.com
     '// April 2003
     '// Works for Xl2000+ due the AddressOf Operator
     '////////////////////////////////////////////////////////////////////
     
     '********************   CALL FROM FORM *********************************
     '    Dim pwd As String
     '
     '    pwd = InputBoxDK("Please Enter Password Below!", "Database Administration Security Form.")
     '
     '    'If no password was entered.
     '    If pwd = "" Then
     '        MsgBox "You didn't enter a password!  You must enter password to 'enter the Administration Screen!" _
     '        , vbInformation, "Security Warning"
     '    End If
     '**************************************
     
     
     
     '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
     
     '// Make it public = avail to ALL Modules
     '// Lets simulate the VBA Input Function
    Public Function InputBoxDK(Prompt As String, Optional Title As String, _
        Optional Default As String, _
        Optional Xpos As Long, _
        Optional Ypos As Long, _
        Optional Helpfile As String, _
        Optional Context As Long) As String
         
        Dim lngModHwnd As Long, lngThreadID As Long
         
         '// Lets handle any Errors JIC! due to HookProc> App hang!
        On Error GoTo ExitProperly
        lngThreadID = GetCurrentThreadId
        lngModHwnd = GetModuleHandle(vbNullString)
         
        hHook = SetWindowsHookEx(WH_CBT, AddressOf NewProc, lngModHwnd, lngThreadID)
        If Xpos Then
            InputBoxDK = InputBox(Prompt, Title, Default, Xpos, Ypos, Helpfile, Context)
        Else
            InputBoxDK = InputBox(Prompt, Title, Default, , , Helpfile, Context)
        End If
         
    ExitProperly:
        UnhookWindowsHookEx hHook
         
    End Function
     
    Sub TestDKInputBox()
        Dim x
         
        x = InputBoxDK("Type your password here.", "Password Required")
        If x = "" Then End
        If x <> "1234" Then
            MsgBox "You didn't enter a correct password."
            End
        End If
         
        MsgBox "Welcome Creator!", vbExclamation
         
    End Sub

    This is the original code my code sprungs out of The problem here is that it's made on a 32 bit system: http://www.mrexcel.com/forum/microso...ss-64-bit.html

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2014
    Posts
    6

    Re: *** mask password in inputbox

    Posted this on other forums; Just for information (got some angry moderators breathing down my neck:
    I have posted this issue on several forums, simply because I don't think it's an easy fix, and most likley It's just a few people who can solve this. Where they are is hard to know, so I have multiplyed the chances of finding them by going wide on the internett Do not worry on dobbeltsolving this problem, the minuite we find a solution its out on every forum. I don not want others to use as much time on this as I have. In fact I hope to mabe make a youtube video But first the problem needs solving So thx anyway for reading, I am quite on my deapth here now, so ain't getting further here without anyone with a little more experience

    Regards
    -Kv

  5. #5
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: *** mask password in inputbox

    Quote Originally Posted by Kvracing View Post
    Hello!

    I am trying to get this access code to work.
    It's for making **** in the field of an inputbox, so the password cant be seen.

    I's originally a code for a 32 bit system, so the real challenge here is converting it to 64 bit.
    Your problem in running this on a 64-bit version of office is that you using "Long" data types where you now need to use "LongPtr".
    I have not worked on a 64-bit version of Office yet, but I know there are some changes that you need to be aware and those are documented in this article.

    64-Bit Visual Basic for Applications Overview

    Your best bet is to look up the original API function on MSDN (search keywords: MSDN FunctionName Function) and identify those parts that are return Hwnd or other handle type that you are currently mapping to VB Long types and use the new LongPtr type.

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2014
    Posts
    6

    Re: *** mask password in inputbox

    Ty, that helped a lot Not there yet though ;/

  7. #7

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2014
    Posts
    6

    Re: *** mask password in inputbox

    Ty for answers, but this took to much time. So I converted to 32 bit. Solved the whole problem

  9. #9
    New Member
    Join Date
    Mar 2018
    Posts
    8

    Re: *** mask password in inputbox

    hi kvracing,

    this is my adaption of your code modification of (with due credit to daniel klann):
    ________________________________________________________________________________________________
    #If VBA7 And Win64 Then
    Private Declare PtrSafe Function CallNextHookEx Lib "user32" (ByVal hHook As LongPtr, _
    ByVal ncode As LongPtr, ByVal wParam As LongPtr, lParam As Any) As Long

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

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

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

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

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

    Private Declare PtrSafe Function GetCurrentThreadId Lib "kernel32" () As Long
    #Else
    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
    #End If

    '~~> 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

    #If VBA7 And Win64 Then
    Private hHook As LongPtr
    #Else
    Private hHook As Long
    #End If

    #If VBA7 And Win64 Then
    Public Function NewProc(ByVal lngCode As LongPtr, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
    #Else
    Public Function NewProc(ByVal lngCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    #End If
    Dim RetVal
    Dim strClassName As String
    #If VBA7 And Win64 Then
    Dim lngBuffer As LongPtr
    #Else
    Dim lngBuffer As Long
    #End If

    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
    RetVal = GetClassName(wParam, strClassName, lngBuffer)
    '~~> Class name of the Inputbox
    If Left$(strClassName, RetVal) = "#32770" Then
    '~~> 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
    #If VBA7 And Win64 Then
    Public Function InputBoxDK(Prompt As String, Optional Title As String, Optional Default As String, _
    Optional XPos As LongPtr, Optional YPos As LongPtr, Optional HelpFile As String, Optional Context As LongPtr) As String
    #Else
    Public Function InputBoxDK(Prompt As String, Optional Title As String, Optional Default As String, _
    Optional XPos As Long, Optional YPos As Long, Optional HelpFile As String, Optional Context As Long) As String
    #End If

    #If VBA7 And Win64 Then
    Dim lngModHwnd As LongPtr, lngThreadID As LongPtr
    #Else
    Dim lngModHwnd As Long, lngThreadID As Long
    #End If
    On Error GoTo ExitProperly

    lngThreadID = GetCurrentThreadId
    lngModHwnd = GetModuleHandle(vbNullString)
    hHook = SetWindowsHookEx(WH_CBT, AddressOf NewProc, lngModHwnd, lngThreadID)
    If XPos Then
    InputBoxDK = InputBox(Prompt, Title, Default, XPos, YPos, HelpFile, Context)
    Else
    InputBoxDK = InputBox(Prompt, Title, Default, , , HelpFile, Context)
    End If

    ExitProperly:
    UnhookWindowsHookEx hHook

    End Function
    ________________________________________________________________________________________________

    i don't know where i went wrong but the password box does not show *, it actually shows the characters keyed in.
    so if i key in "MyPassword", it shows up as "MyPassword".

    i'm using office 32bit in win10 32bit at my workplace and office 64bit on win10 64bit at home.

    would be grateful for kind help from you or anyone (if you have the time).

    best regards,

  10. #10
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: *** mask password in inputbox

    Might be silly but if you are using Access, wasnt there a mask option in one of the properties tabs ?
    However if you really need the API bits to go (I still havent tried yet) you'll need pointersafe and ptrlong. Guess you got that though...


    Oh and use the code tags (the hash button above the text you are typing in).

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  11. #11
    New Member
    Join Date
    Mar 2018
    Posts
    8

    Re: *** mask password in inputbox

    Quote Originally Posted by Ecniv View Post
    Might be silly but if you are using Access, wasnt there a mask option in one of the properties tabs ?
    However if you really need the API bits to go (I still havent tried yet) you'll need pointersafe and ptrlong. Guess you got that though...


    Oh and use the code tags (the hash button above the text you are typing in).
    _________________________________________________________________________

    i'm using the code in excel vba. i've a dashboard with a few command buttons, each for a different purpose in excel data retrieval. what i want is only authorized personnel to access the data as it contains some sensitive employee information. because we use only office 2007, i thought of incorporating a password through input box which is why i borrowed the daniel klann code modified by kvracing.

    this code throws up the inputbox all correct but it doesn't mask the characters with "*", defeating its very purpose. on a note, as i use office 32bit on win10 32bit at workplace and office 64bit on win10 64bit at home, i figured the "#if vba7 and win64" part myself.

    hope i get some help soon.

  12. #12
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: *** mask password in inputbox

    Excel User form input control?

    Check your properties > catergorized > appearance > Password Char

    Same if you inserted on a sheet direct....


    Not sure why you'd need the API apart from testing and practicing.

    Good luck with the pointer safe and long pointers for the 64 bit...

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  13. #13
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: *** mask password in inputbox

    surely you could use a small user form with a textbox and a couple of buttons?
    or one of excels built in dialogs
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  14. #14
    New Member
    Join Date
    Mar 2018
    Posts
    8

    Re: *** mask password in inputbox

    Quote Originally Posted by westconn1 View Post
    surely you could use a small user form with a textbox and a couple of buttons?
    or one of excels built in dialogs
    that was not exactly the issue i face. whether the user form is small or big hardly matters.

    what matters is what is accessed through that form. and the form — presented as a dashboard — has different prompts (in the form of command buttons) for different types of employee data retrieval. normally, when one presses one of the prompt, say, Retrieve Personal Information, then excel does just what the prompt (command button) says! IF THE VBA CODE WASN'T DONE, then the data retrieval happens just about by anyone that has access to the excel sheet, which has to be kept open because it's a large workbook with a lot of sheets of loads of employee data and takes about one and a half minutes to two just to be up and running. I HOPE THIS CLEARS THE AIR ABOUT WHAT THE EXCEL DASHBOARD DOES!

    because we require the excel sheet to be open 9 to 5.30, the only solution we could implement to PROTECT DATA RETRIEVAL from prying eyes was to password protect the command button pressing. that way, we could make sure only those employees can access the data that have been given the password, viz., the employees of the hr department.

    **update**
    no, i haven't been able to get it to work but i'm trying hard because for now, i've password-protected the workbook itself so it asks for password to open. again, the employees authorized to run the data retrieval have to close it once their task is over only to open it again for another different task. so they're prompted for a password to open every time and they need to close the workbook too everytime. this makes it eat up a lot of our office time for nothing.

    that's why keeping the workbook open during office hours while protecting data retrieval with a password is the best option.
    Last edited by zambi007; Mar 23rd, 2018 at 09:27 AM. Reason: update status

  15. #15
    New Member
    Join Date
    Mar 2018
    Posts
    8

    Re: *** mask password in inputbox

    Quote Originally Posted by Ecniv View Post
    Excel User form input control?

    Check your properties > catergorized > appearance > Password Char

    Same if you inserted on a sheet direct....

    Not sure why you'd need the API apart from testing and practicing.

    Good luck with the pointer safe and long pointers for the 64 bit...
    ____________________________________________________________________

    the api you refer is part of the coding daniel klann created.
    the point here is to create an inputbox that asks for user input.

    the longptr type and ptrsafe declaration are needed because both #vba7
    and #win64 vba constants are true in a 64-bit environment.

    if both return true then that's 64-bit office on a 64-bit windows the code
    will be run on. if both return null then that's 32-bit office on a 32-bit
    windows. however, if win64 returns true while vba7 returns null then
    that's 32-bit office on a 64-bit windows.

    because the vba default inputbox(...) function doesn't mask characters
    it'd be obvius it'd reveal if we try to use it natively to enter some password.
    the workaround is to call inputbox and then check if it's active and ready
    for keypress. when that happens, the senddlgitemmessage masks the input
    characters with a "*" thus protecting the password from prying eyes.
    excel natively doesn't have any "passwordbox" or "passwordprompt" built
    in which is why the coding referred above is supposed to do that with the
    help of api definitions. actually, it does much more than that. it checks if
    inputbox called is active for user input, then sends "*" characters for each
    key the user types in. for instance, my password might be "check", but
    for each of the character in "check", the inputbox shows a "*" so it shows
    "*****" instead of the word "check".

    that way, if any unauthorized personnel tried to access the form, because
    s/he doesn't know that the password is "check", s/he would not be able to
    access the employee data only authorized users are supposed to

    i suppose i've made it clear why this coding is necessary. the problem is
    the code runs well to ask for input but shows up whatever characters are
    typed, in this example, the password "check" shows up as "check" instead
    of "*****".

    i don't know if it's a 64-bit issue or not, i can't speculate on that but i'd
    need help here as the coding behaves the same in a 32-bit environment
    too which is why it's gone way over my head.

  16. #16
    New Member
    Join Date
    Mar 2018
    Posts
    8

    Re: *** mask password in inputbox

    hi all!

    i'm posting again for any help.

    **update**
    the coding works perfectly in a 32-bit environment. so no issues there.
    for the 64-bit, i just have no idea what's going wrong where!

  17. #17
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: *** mask password in inputbox

    i thought of having a look at it, but as i do not have a 64 bit office, i'm out
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  18. #18
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: *** mask password in inputbox

    because the vba default inputbox(...) function doesn't mask characters
    ...but it does.. its in the (pop up) properties tab under appearence.

    This is why I'm asking whether you really need to delve into api calls. Yeah they are interesting and it is very satisfying when they work. But they can also be a major headache. Are you typing into a textbox you created on a userform or dropped on a spreadsheet. Or are you on about a different place to enter a password?

    as to your code in the vba 7 - if it is displaying the text myPasswordChar then there is something wrong with the part where you set the character into the api.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  19. #19
    New Member
    Join Date
    Mar 2018
    Posts
    8

    Re: *** mask password in inputbox

    ...but it does.. its in the (pop up) properties tab under appearence.

    you are correct. thanx very much ecniv.

    but i believe, that it has to do with the way you use the function inputbox itself. for using the passwordchar property, you first need to design a form that has the inputbox control and then modify its property to use the passwordchar attribute set to your choice of "*".

    to use an inputbox function simply through coding, you don't need to design any form and put an inputbox control in it, but simply copy/paste the api coding and then call inputboxdk to simulate a password entry.

    whereas i could use the form design too, which is also useful as it does the same function without the necessity of long coding. and it works both on 32-bit and 64-bit without any modifications.

    i'd just need to see whether it can be (ctrl-break)ed because in such a case, it'd defeat the very purpose. could you shed some light on this?

    thanx again for the help.
    Attached Images Attached Images  

  20. #20
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: *** mask password in inputbox

    Password the VBA too ?
    To be honest I've never tried to ctrl+break the user forms. But if you've protected the vba coding the users shouldn't be able to mess with your code (or see if?).

    Depends if you think your users will try to look at how it works, break it. Access and Excel people have said in the past can be broken but I believe you need specific tools and a lot of time. Perhaps others can assist with this part.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  21. #21
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: *** mask password in inputbox

    If the code needs to be protected, maybe it's time to pull it out of the spreadsheet and create an actual application.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  22. #22
    New Member
    Join Date
    Mar 2018
    Posts
    8

    Re: *** mask password in inputbox

    Quote Originally Posted by techgnome View Post
    If the code needs to be protected, maybe it's time to pull it out of the spreadsheet and create an actual application.

    -tg
    LOL! just need to retrieve employee details and their benefit accruals, leave availed etc before i even venture out for external app coding. excel does just what we need, so i'd keep onto it now.

  23. #23
    New Member
    Join Date
    Mar 2018
    Posts
    8

    Re: *** mask password in inputbox

    Quote Originally Posted by Ecniv View Post
    Password the VBA too ?
    To be honest I've never tried to ctrl+break the user forms. But if you've protected the vba coding the users shouldn't be able to mess with your code (or see if?).

    Depends if you think your users will try to look at how it works, break it. Access and Excel people have said in the past can be broken but I believe you need specific tools and a lot of time. Perhaps others can assist with this part.
    yep. for now i got the coding to work on 32-bit office quite well and it serves my purpose of employee details retrieval. just thought it'd be better to let go of the devil (office 64-bit) instead of trying to bring the hell (ptrsafe) to me. LOL!

  24. #24
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: *** mask password in inputbox

    i do not see there is any difference, as far as security is concerned, using a userform or an inputbox, in either case the code can be viewed easily (even when passworded), it will show what is done with the password (how it is validated) after it is entered, regardless of whether the password can be viewed on screen, it is unlikely that crtl brk, would make any help on a userform, if the approved user is still sitting at the keyboard, hiding the password on screen has some benefit, but is unlikely to stop anyone who really wants to get to the excel data, if security is critical, a strongly passworded database may be a better option

    there was a thread yesterday in vb6 forum where someone showed some sample code that was contained in a passworded excel vba project, so had obviously cracked or bypassed the password
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width