Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Binary Files Tutorial
#1
http://ms.shannaracorp.com/backup-forum ... asp?TID=46

I'm stuck at the PasswordOK Function.
Quote:PasswordOK... we need to break out that file again... sigh... time to learn something a little more complicated... slowly Smile

Two declares at the top this time, one to hold the password we get out of the file and one to hold the file number.

Dim RightPassword As String * NAME_LENGTH
Dim nFileNum As Integer



Notice that it's a constant length? This prevents us from needed to store the length of it with us. Convinient Smile

nFileNum = FreeFile
Open FileName For Binary As #nFileNum



Open that bad boy up, inside the If AccountExist statement.. Remember to change your file extention to your cool file extention, because .ini is lame!

Now we get to the slightly new part.

Get #nFileNum, 20, RightPassword



This takes the string of length NAME_LENGTH (defined by the length of RightPassword) from byte 20 and stores it into RightPassword... .got that? It's tough...

How do I know to start at byte 20? I counted. I know that the password is stored after the login, which is also a constant length string of length 20 bytes. It uses bytes 0-19 so the first character of the password must be stored on byte 20. The function automaticly does the rest Smile

Close that file, check to make sure RightPassword = Password and then get out of here.

The Function PasswordOK
Quote:Function PasswordOK(ByVal Name As String, ByVal Password As String) As Boolean
Dim FileName As String
Dim RightPassword As String * NAME_LENGTH
Dim nFileNum As Integer


PasswordOK = False

If AccountExist(Name) Then
nFileNum = FreeFile
Open FileName For Binary As #nFileNum
FileName = App.Path & "\accounts\" & Trim(Name) & ".ini"
RightPassword = GetVar(FileName, "GENERAL", "Password")

If UCase(Trim(Password)) = UCase(Trim(RightPassword)) Then
PasswordOK = True
End If
End If
End Function

QUESTION"
Where would I put
Get #nFileNum, 20, RightPassword

Please Help.. Thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)