DaveHa
asked on
Checksum
I can write 10 character in the password textbox and get access, but i only send in 8 character in the makekey..what's wrong ?
Thanks for help!
//Dave
Function iicsa(ch As String) As Long
Dim sList As String
sList = "_0123456789ABCDEFGHIJKLMN OPQRSTUVWX YZabcdefgh ijklmnopqr stuvwxyz"
iicsa = InStr(1, sList, c) - 1
End Function
Function CheckPassword(checkSum As Long) As Boolean
Dim passWd As String
Dim q As Long
Dim n As Long
passWd = txtPassword.Text
For n = 1 To Len(passWd)
q = q Xor iicsa(Mid(passWd, n, 1))
Next
If (q = checkSum) Then
Unload Me
mdiMain.Show
Else
CheckPassword = False '<<==
MsgBox "Wrong password!" & vbCrLf & "", vbCritical, ""
End
End If
End Function
Function makekey(passWd As String) As Long
Dim q As Long
Dim n As Long
q = 0
For n = 1 To Len(passWd)
q = q Xor iicsa(Mid(passWd, n, 1))
Next
makekey = q
End Function
Private Sub cmdCancel_Click()
Unload frmPassword
End Sub
Private Sub cmdOk_Click()
Dim key As Long
key = makekey("54432323")
Debug.Print CheckPassword(key)
End Sub
Private Sub Timer2_Timer()
If txtPassw = "" Then
cmdOk.Enabled = False
Else
cmdOk.Enabled = True
End If
End Sub
Private Sub txtPassw_KeyPress(keyascii As Integer)
keyascii = Asc(UCase$(Chr(keyascii)))
If keyascii = 13 Then cmdOk_Click
End Sub
Private Sub Timer1_Timer()
Static dtmintialTime As Date
If dtmintialTime = 0 Then
dtmintialTime = Now
ElseIf DateAdd("n", 5, dtmintialTime) < Now Then
MsgBox "End", vbInformation, ("Info")
dtmintialTime = Now
End
End If
End Sub
Thanks for help!
//Dave
Function iicsa(ch As String) As Long
Dim sList As String
sList = "_0123456789ABCDEFGHIJKLMN
iicsa = InStr(1, sList, c) - 1
End Function
Function CheckPassword(checkSum As Long) As Boolean
Dim passWd As String
Dim q As Long
Dim n As Long
passWd = txtPassword.Text
For n = 1 To Len(passWd)
q = q Xor iicsa(Mid(passWd, n, 1))
Next
If (q = checkSum) Then
Unload Me
mdiMain.Show
Else
CheckPassword = False '<<==
MsgBox "Wrong password!" & vbCrLf & "", vbCritical, ""
End
End If
End Function
Function makekey(passWd As String) As Long
Dim q As Long
Dim n As Long
q = 0
For n = 1 To Len(passWd)
q = q Xor iicsa(Mid(passWd, n, 1))
Next
makekey = q
End Function
Private Sub cmdCancel_Click()
Unload frmPassword
End Sub
Private Sub cmdOk_Click()
Dim key As Long
key = makekey("54432323")
Debug.Print CheckPassword(key)
End Sub
Private Sub Timer2_Timer()
If txtPassw = "" Then
cmdOk.Enabled = False
Else
cmdOk.Enabled = True
End If
End Sub
Private Sub txtPassw_KeyPress(keyascii
keyascii = Asc(UCase$(Chr(keyascii)))
If keyascii = 13 Then cmdOk_Click
End Sub
Private Sub Timer1_Timer()
Static dtmintialTime As Date
If dtmintialTime = 0 Then
dtmintialTime = Now
ElseIf DateAdd("n", 5, dtmintialTime) < Now Then
MsgBox "End", vbInformation, ("Info")
dtmintialTime = Now
End
End If
End Sub
what's the problem?
ASKER
Well the makekey password is 8 character long "54432323" in this example, if typ more than 8 char like "5443232311" i can still pass in to the programme.
Hope you understand my problem.
Hope you understand my problem.
I'm not sure anything is wrong, if you enter a password ending in "xx" then it will XOR twice meaning that the xx at the end has no effect.
Function CheckPassword(checkSum As Long) As Boolean
Dim passWd As String
Dim q As Long
Dim n As Long
passWd = txtPassword.Text
For n = 1 To Len(passWd)
q = q Xor iicsa(Mid(passWd, n, 1))
Next
If (q = checkSum and len(passwd) = 8) Then
Unload Me
mdiMain.Show
Else
CheckPassword = False '<<==
MsgBox "Wrong password!" & vbCrLf & "", vbCritical, ""
End
End If
Function CheckPassword(checkSum As Long) As Boolean
Dim passWd As String
Dim q As Long
Dim n As Long
passWd = txtPassword.Text
For n = 1 To Len(passWd)
q = q Xor iicsa(Mid(passWd, n, 1))
Next
If (q = checkSum and len(passwd) = 8) Then
Unload Me
mdiMain.Show
Else
CheckPassword = False '<<==
MsgBox "Wrong password!" & vbCrLf & "", vbCritical, ""
End
End If
I do understand your problem. First of all I hope the c in
iicsa = InStr(1, sList, c) - 1
is a typo that you don't have in your original code (c is undefined so no matter what you want to evaluate, you'll get a value of 0. It should of course be ch.
Even if this is the case consider this:
560 XOr 4=564
564 XOr 4=560
In other words, if you to type the password followed by an even number of identical numbers, your expression will evaluate to true
I don't know whether you can except this as an answer or that you need an example of how to correct it? (I could provide you with one, but I need some time for it)
iicsa = InStr(1, sList, c) - 1
is a typo that you don't have in your original code (c is undefined so no matter what you want to evaluate, you'll get a value of 0. It should of course be ch.
Even if this is the case consider this:
560 XOr 4=564
564 XOr 4=560
In other words, if you to type the password followed by an even number of identical numbers, your expression will evaluate to true
I don't know whether you can except this as an answer or that you need an example of how to correct it? (I could provide you with one, but I need some time for it)
Oh, one other thing.
Your function only checks the combination of charcters, not the order.
In other words, when you insert the password "Hello" in the makekey function and someone enters "loHel" in the editbox, the checksums will match and the user can enter!
Your function only checks the combination of charcters, not the order.
In other words, when you insert the password "Hello" in the makekey function and someone enters "loHel" in the editbox, the checksums will match and the user can enter!
ASKER
Oh!, how do i check the order?
ASKER
Yes if you have time to provide me a example i would be very thankful.
I have, check back in in about an hour or two. (unless someone else has got something useful of course)
See ya
See ya
Why do you need to use a checksum? Could you not just compare withy the password using = ?
Am I missing something?
Am I missing something?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.