Catalyst Gaming
General => Support & Help => Topic started by: [GM] I Eat Chich on January 30, 2012, 03:21:04 PM
-
Hello all, i have no idea if this code works because it is using a file that i created using a program which doesn't work (because of a bad record length, i'll have to ask my teacher tomorrow) basically, it opens a random access file (the one that was meant to be created before) and then compares the inputted details from the user to it to make sure the password/username match. please have a look and please tell me if i've done anything wrong :)
Option Explicit On
Imports System.IO
Module Module1
Structure Users
<VBFixedString(16)> Dim strUsername As String
<VBFixedString(16)> Dim strPassword As String
Dim charAccountType As Char
End Structure
Sub Main()
'declares the variables
Dim strEnterPassword, strEnterUsername, FileName As String
Dim blnCheck, blnUserCheck As Boolean
Dim intAttempts, NoOfRecords As Integer
Dim arrUserdetails As Users
Dim noOfRecords As Integer
Dim pos As Integer
pos = 0
FileName = "Datastore.dat"
FileOpen(1, FileName, OpenMode.Random, , , Len(arrAccount))
noOfRecords = LOF(1) / len(arrAccount)
'initialises the variables
strEnterPassword = ""
strEnterUsername = ""
blnCheck = False
intAttempts = 0
blnUserCheck = False
Do While Not EOF(1)
FileGet(1, arrAccount)
Loop
Console.WriteLine("Enter your username")
strEnterUsername = Console.ReadLine()
Do Until blnUserCheck = True Or pos = noOfRecords + 1
If strEnterUsername = arrAccount.strUsername(pos) Then
blnUserCheck = True
Else
pos = pos + 1
End If
Loop
If pos = noOfRecords + 1 Then
Console.WriteLine(strEnterUsername & " " & "is not a valid username")
ElseIf blnUsercheck = True Then
'sets up a loop that will finish when the statement becomes true or if it has been attempted 3 times
Do Until blnCheck = True Or intAttempts = 3
'asks the user to input their details
intAttempts = intAttempts + 1
Console.WriteLine("You have" & " " & 4 - intAttempts & " " & "attempts remaining.")
Console.WriteLine("Enter your password")
strEnterUsername = Console.ReadLine()
'checks if the statement is true or false, and outputs a relevant message
If strEnterPassword = arrUserdetails.strPassword(pos) Then
blnCheck = True
Console.WriteLine("Access granted")
Console.Read()
Else
Console.WriteLine("Details incorrect, please try again.")
Console.Read()
End If
Loop
'tells the user the attempts have been exceeded
If intAttempts = 3 Then
Console.WriteLine("You have exceeded the amount of password attempts.")
Console.ReadLine()
Else
Console.WriteLine("Access granted.")
Console.ReadLine()
End If
End If
End Sub
End Module
-
This looks like you used a VB code on somphing that dosn't use the VB code, If its a data base I dont undersand what you have put, Most of it is errors and its too much to help you with, Sorry.
-
Get a cleaner writing style, make it easily readable and documented.