Results 1 to 10 of 10

Thread: excel Password algorithm

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    USA, East Coast
    Posts
    257

    excel Password algorithm

    Hello,

    For an Excel VBA app, is this the accepted way to check a password? (No Access involved - just a straight Excel app)

    In a hidden cell on a hidden Worksheet, I put the password. Using the Worksheet Function MATCH, I check what the password is against what the User entered into the Textbox.
    If correct, give them access to whatever, If incorrect, notify and let them try again.

    Is this the way it is usually done?

    Thanks for any advice,
    CJ

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    If the user deletes the worksheet after unhiding it there will be
    no password verification at all. It may be better to add a class to
    your Excel VBA that will hold the password. and in the
    Open_Workbook event, or similar, you can prompt for the
    password and validate it. You can protect the code from being
    viewed by clicking (in VBA) the Tools > VBAProject Properties... >
    Protection tab > and check the "Lock project for viewing" box and
    supply a password. Don't forget it because there is now way to
    reset it or retrieve it once you forget it.

    HTH
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    USA, East Coast
    Posts
    257
    Your way is very professional of course.

    If I put the password on the Data worksheet, it will not get deleted (if that page is deleted, then there is no app)

    On second thought as I'm typing , the cell containing the password may get erased accidentally by some Administrator.

    What if I hardcode the password value, then lock the project for viewing only.

    CJ

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    What if I hardcode the password value, then lock the project for viewing only.
    The answer is yes.
    Much better.

    Just make sure to write the password down and before you lock
    the project make a backup copy without locking, just in case.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126
    If you are coding your password into VBA, try and keep it within a subroutine, as a local variable. For best practices, only the code subroutine that requires access to it should be able to see it.

    And then it goes without saying of locking your project.

    I have also seen using names to store variables. You can also hide the name from being visible. Not as secure, but few people tend to look for hidden names. Use this if you require access to your password from many different components of your project.
    -----
    #VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP

    I miss my VIC 20.
    Never should have upgraded to my commodore 64. ...

  6. #6
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126
    you also asked what was the accepted way to check for a password.

    this is likely what I would use, coding in a vba module.

    VB Code:
    1. Sub password()
    2. Dim password As String
    3. Dim i As Integer
    4. Dim x As String
    5. password = "Unlock" ' case sensitive
    6. For i = 1 To 3
    7. x = InputBox("Enter correct password", vbYesNo)
    8. If x = password Then
    9.     MsgBox "You have just won absolutely nothing! Congratulations!", vbOKOnly, "System Password"
    10.     Exit For
    11.     Else
    12.     MsgBox "You lost", vbOKOnly, "System Password"
    13.     End If
    14. Next
    15. End Sub

    If you choose to still go with a cell stored variable, you can still use this with password just referencing the cell.
    The i is used to give the user three tries before it exits the loop.
    -----
    #VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP

    I miss my VIC 20.
    Never should have upgraded to my commodore 64. ...

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    USA, East Coast
    Posts
    257
    Thanks for the replies.

    Fiddler, I see that in your code you use an InputBox to capture the User's password. So you don't use the '*' input mask?

    I had considered using an InputBox, but instead made a UserForm with a TextBox, Label, an Ok and a Cancel button. For all that overhead, I would have preferred a simple InputBox but because of the lack of an input mask I chose the UserForm.

    I think the asterisks make the Users *feel* more secure, although it's a false sense of security.

    CyberJar

  8. #8
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126
    I guess it depends on your users.

    Masked text boxes ("*****") are nice for session logon, gaining access to certain parts of the program, etcs.. I use these within my program at many points, say to restrict access to a price grid, or to view cost information.

    Unmasked password boxes are often used when the password is more complex, involving many characters, and upper and lower case combinations. I would use if coding an install password that responds to the users' serial number. I would likely not use for a day to day system use password.
    In my install routine, it involves a 16 to 20 digit code that the user has to type in. I always try to get the user to read it back to me so that I don't have to go through the routine twice. Hence, visible characters reduce the errors.
    -----
    #VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP

    I miss my VIC 20.
    Never should have upgraded to my commodore 64. ...

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    USA, East Coast
    Posts
    257
    Good points on when to use visible passwords.

    For my app, most Users are not going to use the Password feature - only Admin types when data changes - which is not too often.

    Thanks to both you & Robdog888 for the assist,
    CyberJar

  10. #10
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048
    never hard code a password... you can open the file in notepad and see it

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