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 = "_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
    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









DaveHaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

alokanantCommented:
what's the problem?
0
DaveHaAuthor Commented:
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.
0
deightonprogCommented:
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
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

p_biggelaarCommented:
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)
0
p_biggelaarCommented:
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!
0
DaveHaAuthor Commented:
Oh!, how do i check the order?
0
DaveHaAuthor Commented:
Yes if you have time to provide me a example i would be very thankful.
0
p_biggelaarCommented:
I have, check back in in about an hour or two. (unless someone else has got something useful of course)

See ya
0
deightonprogCommented:
Why do you need to use a checksum?  Could you not just compare withy the password using = ?

Am I missing something?
0
p_biggelaarCommented:
Deighton is right in the way you use it now, but if you want to store the encrypted password or something, you can use a checksum or something that looks like this:

1) This example is very basic and uses 'the same 'mask' every time:

Private Sub Command1_Click()
Dim Mykey As String
    Mykey = makekey("Password")
    If CheckPassword(Text1.Text, Mykey) = True Then
        MsgBox "Correct pwd"
    Else
        MsgBox "Wrong pwd"
    End If
End Sub

Function makekey(strPwd As String) As String
Dim intCounter As Integer
Dim intChkX As Integer
Dim intKey As Integer
Dim strChecksum As String

    intKey = 256
    strChecksum = ""
    For intCounter = 1 To Len(strPwd)
        intChkX = intKey Xor Asc(Mid(strPwd, intCounter, 1))
        strChecksum = strChecksum & CStr(intChkX)
    Next
    makekey = strChecksum

End Function

Function CheckPassword(strPwd As String, key As String)
    If key = makekey(strPwd) Then
        CheckPassword = True
    Else
        CheckPassword = False
    End If
End Function


2) This function uses a randomly generated key every time you call the makekey procedure(without providing a value for keyValue)

Private Sub Command1_Click()
Dim Mykey As String
    Mykey = makekey("Password")
    If CheckPassword(Text1.Text, Mykey) = True Then
        MsgBox "Correct pwd"
    Else
        MsgBox "Wrong pwd"
    End If
End Sub

Function makekey(strPwd As String, Optional keyValue As Variant) As String
Dim intCounter As Integer
Dim intChkX As Integer
Dim intKey As Integer
Dim strChecksum As String

    Randomize
    If IsMissing(keyValue) = True Then 'no value supplied
        intKey = Rnd * 256 + 256
    ElseIf CInt(keyValue) < 256 Then 'incorrect value supplied (maybe you want it to react differently
        intKey = Rnd * 256 + 256
    Else 'a correct value supplied
        intKey = keyValue
    End If
   
    strChecksum = ""
    For intCounter = 1 To Len(strPwd)
        intChkX = intKey Xor Asc(Mid(strPwd, intCounter, 1))
        strChecksum = strChecksum & CStr(intChkX)
    Next
    makekey = CStr(intKey) & strChecksum

End Function

Function CheckPassword(strPwd As String, key As String)
    If key = makekey(strPwd, Left(key, 3)) Then
        CheckPassword = True
    Else
        CheckPassword = False
    End If
End Function

These examples show you how you can easily encrypt/check passwords.

Of course these are only simple examples, but I hope it's enough for you at the moment. If not I'll be hearing from you.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.