kelly mort
Well-known Member
- Joined
- Apr 10, 2017
- Messages
- 2,169
- Office Version
- 2016
- Platform
- 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..
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