Best way to authenticate logins with vba code

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Hello Geniuses,

Assuming I am using the code below to hash my password and store the hashed password in a table(hidden Worksheet), at login,

A password like "@money20", is hashed as "9DF1ACAD45DA".

At login, is it good to authenticate the password like this:

If hash12 (userpwd) = hashedPwd
???

If that's cool please do let me know and if that's a bad thing, please do let me know as well..



Code:
Sub tester()
    Dim myInput$
    myInput = "money"
    'MsgBox hash4(myInput)
    MsgBox hash12(myInput)
End Sub


Function hash12(s$)
    Dim l%, l3%, s1$, s2$, s3$
    l = Len(s)
    l3 = Int(l / 3)
    s1 = Mid(s, 1, l3)
    s2 = Mid(s, l3 + 1, l3)
    s3 = Mid(s, 2 * l3 + 1)
    hash12 = hash4(s1) + hash4(s2) + hash4(s3)
End Function

Function hash4(txt)
    Dim x&, mask, i, j, nC, crc%, c$
    crc = &HFFFF
    For nC = 1 To Len(txt)
        j = Asc(Mid(txt, nC))
        crc = crc Xor j
        For j = 1 To 8
            mask = 0
            If crc / 2 <> Int(crc / 2) Then mask = &HA001
            crc = Int(crc / 2) And &H7FFF: crc = crc Xor mask
        Next j
    Next nC
    
    c = Hex$(crc)

    While Len(c) < 4
      c = "0" & c
    Wend
    
    hash4 = c
End Function
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi,​
it's 'cool' if only the VBA project is protected but as this 'protection' can be bypassed …​
 
Upvote 0
Solution
Hi,​
it's 'cool' if only the VBA project is protected but as this 'protection' can be bypassed …​
So what is the best way to handle this kind of situation?
 
Upvote 0
Why shoud you need some specific VBA password rather than the password at workbook level (best protection) ?​
 
Upvote 0
Why shoud you need some specific VBA password rather than the password at workbook level (best protection) ?​
I am trying things out. And I am glad to learn from you that the workbook protection is more secured compared to the others.

Have a wonderful weekend.
 
Upvote 0
Yes since Excel 2013 (or 2010 if updated).​
For VBA level as it is, that's weak but exist some add-ins …​
 
Upvote 0
If you use a secure hash like SHA, then hashing the password makes a lot of sense.

As has been said, however, the VBA code needs to be password protected, otherwise your code can be bypassed. It is possible to crack VBA passwords quite easily using a trick that can be found on the net, so that is not foolproof. But in most situations, protected VBA code is probably good enough.
 
Upvote 0
Before I use the SHA, do I need to install any forms of frameworks?

I have tried a few of the hashes and I get automation error.
If you use a secure hash like SHA, then hashing the password makes a lot of sense.

As has been said, however, the VBA code needs to be password protected, otherwise your code can be bypassed. It is possible to crack VBA passwords quite easily using a trick that can be found on the net, so that is not foolproof. But in most situations, protected VBA code is probably good enough.
 
Upvote 0
Before I use the SHA, do I need to install any forms of frameworks?

I have tried a few of the hashes and I get automation error.

Seek and ye shall find....
 
Upvote 0
Seek and ye shall find....

I read that article last time and the one with the hash4 and hash12 functions aroused something in me - I never thought vba could do such stuffs.

And testing the StrHash and StrHash64, I am speechless.

I appreciate your time. Have a wonderful time.
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,843
Members
449,193
Latest member
MikeVol

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top