Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passwords not matching according to the program but they do? 1

Status
Not open for further replies.

gwar2k1

Programmer
Apr 17, 2003
387
GB
Hey, Im using a flat file to store details of an administrator (username, password, and some file settings). The password gets converted letter by letter to hex and has 11hex added to each. It is then stored in this format. When comparing an input password against the stored one, the conversion of the input one matches, but it shows an error (my program, not VB6) saying they dont match.

This is the code for the 'encryption' and comparing:

Public Function strHex(convert As String) As String

Dim index As Integer
Dim strShort As String

For index = 1 To Len(convert)
strShort = Mid(convert, index, 1)
strHex = strHex + (Hex$(Asc(strShort)) & Hex$(11))
Next
MsgBox (strHex)

End Function

Public Function loginAdmin() As Boolean
Rem validates the password entered admin details

Dim AdminRec As AdminRecord

loginAdmin = True
Open flpath & flName For Random As #1
Get #1, 1, AdminRec
If (MOSgui.txtUserName <> RTrim(AdminRec.UserName)) Then
MsgBox (&quot;Invalid user&quot;)
loginAdmin = False
End If
If (RTrim(MOSgui.txtPassword) <> AdminRec.PassWord) Then
MsgBox (&quot;invalid password&quot;)
loginAdmin = False
End If
Close #1

End Function


Im hoping someone can point out what's wrong cause even though ive checked and checked i cant see anything wrong. I even split it up into invalid user / password to determine which comparison was causing the problem. Any help is appreciated.

TIA

~*Gwar3k1*~
&quot;To the pressure, everything's just like: an illusion. I'll be losing you before long...&quot;
 
Hi.

I think from what i understand you code needs to be more like this

Public Function strHex(convert As String) As String

Dim index As Integer
Dim strShort As String
Dim strLetter As String
Dim valLetter As Integer


For index = 1 To Len(convert)
strShort = Mid(convert, index, 1) 'Extract each character
valLetter = Asc(strShort) + 11 ' Get the ascii value of each character and add 11 (decimal)
strLetter = Hex(valLetter) ' Convert the value into hex
strHex = strHex & strLetter ' Add the hexadecimal version to the end of the string
Next
MsgBox (strHex)
End Function

This code can be optimized.

Also note that if you want to add on 11 hex raher than 11 decimal then the line
valLetter = Asc(strShort) + 11
should be replaced by
valLetter = Asc(strShort) + 17


HTH

Dave
 
hmm... i changed it a little to do it the optimised way you suggested but left my msgbox at the end... the msgbox now isnt displayed...

Public Function strHex(convert As String) As String

Dim index As Integer
Dim strShort As String

For index = 1 To Len(convert)
strShort = Mid(convert, index, 1)
strHex = strHex + (Hex(Asc(strShort) + 11))
Next
MsgBox (strHex)

End Function

~*Gwar3k1*~
&quot;To the pressure, everything's just like: an illusion. I'll be losing you before long...&quot;
 
It works for me.

Ok try this as a demo. Start a new project with a textbox (Text1) and a command button (Command1)

and use this code:

Private Sub Command1_Click()
strHex Text1.Text
End Sub

Public Function strHex(convert As String) As String

Dim index As Integer
Dim strShort As String

For index = 1 To Len(convert)
strShort = Mid(convert, index, 1)
strHex = strHex + (Hex(Asc(strShort) + 11))
Next
MsgBox (strHex)

End Function
Type something into the textbox for example Dave, you should get a message box pop up with the answer 4F6C8170 in it

Dave
 
Apart from the encoding issues, covered above..

How is AdminRec defined?

You read it all in at once using GET# , but have you tried putting a messagebox straight after reading it just to confirm that Adminrec.username (for example) holds what you think it does?
What happens if the username is a variable length string, for instance?
(eg GOD or MYGOODNESSWHATALONGNAME)
Your StrHex function does not pad it to a fixed length...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top