[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Checksum

Posted on 2000-02-04
10
Medium Priority
?
606 Views
Last Modified: 2008-02-26
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









0
Comment
Question by:DaveHa
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 2

Expert Comment

by:alokanant
ID: 2489123
what's the problem?
0
 

Author Comment

by:DaveHa
ID: 2489193
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
 
LVL 18

Expert Comment

by:deighton
ID: 2489197
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 2

Expert Comment

by:p_biggelaar
ID: 2489231
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
 
LVL 2

Expert Comment

by:p_biggelaar
ID: 2489240
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
 

Author Comment

by:DaveHa
ID: 2489333
Oh!, how do i check the order?
0
 

Author Comment

by:DaveHa
ID: 2489346
Yes if you have time to provide me a example i would be very thankful.
0
 
LVL 2

Expert Comment

by:p_biggelaar
ID: 2489439
I have, check back in in about an hour or two. (unless someone else has got something useful of course)

See ya
0
 
LVL 18

Expert Comment

by:deighton
ID: 2489528
Why do you need to use a checksum?  Could you not just compare withy the password using = ?

Am I missing something?
0
 
LVL 2

Accepted Solution

by:
p_biggelaar earned 240 total points
ID: 2489632
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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question