Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System
- Imports System.Security.Cryptography
- Imports System.Text
- Module Module1
- Structure formBlueprint
- Dim id As Integer
- Dim name As String
- Dim teacher As String
- Dim year As Integer
- Dim password As String
- End Structure
- Structure userblueprint
- Dim id As Integer
- Dim username As String
- Dim password As String
- Dim fname As String
- Dim sname As String
- Dim form As String
- Dim age As Integer
- Dim points As Integer
- End Structure
- Dim activeUser As userblueprint
- Dim userdb(100) As userblueprint
- Dim formuser As formBlueprint
- Dim formdb(100) As formBlueprint
- Sub main()
- readfileuser()
- readfileform()
- Do
- Console.Clear()
- Console.WriteLine("Teacher - 1")
- Console.WriteLine("Student - 2")
- Dim choice As Integer = Console.ReadLine
- If choice = 1 Then
- formMenu()
- End If
- If choice = 2 Then
- usermenu()
- End If
- Loop
- End Sub
- Sub pointarea()
- Console.WriteLine("1 - Check points:")
- Console.WriteLine("2 - spend points")
- End Sub
- Sub usermenu()
- readfileuser()
- activeUser = Nothing
- Do
- Console.Clear()
- Console.WriteLine("1 - Add User")
- Console.WriteLine("2 - Login")
- If activeUser.username <> Nothing Then
- Console.WriteLine("3 - Delete " + activeUser.username)
- Console.WriteLine("4 - Edit, check points and spend points " + activeUser.username)
- End If
- Console.WriteLine("5 - Exit")
- Dim choice As Integer = Console.ReadLine
- If choice = 1 Then
- adduser()
- End If
- If choice = 2 Then
- LoginUser()
- End If
- If choice = 3 Then
- deleteuser()
- End If
- If choice = 4 Then
- edituser()
- End If
- If choice = 5 Then
- Exit Sub
- End If
- Loop
- End Sub
- Sub formMenu()
- readfileform()
- formuser = Nothing
- Do
- Console.Clear()
- Console.WriteLine("1 - Add form")
- Console.WriteLine("2 - Login")
- If formuser.name <> Nothing Then
- Console.WriteLine("3 - Delete form " + formuser.name)
- Console.WriteLine("4 - Edit form and add points to students " + formuser.name)
- End If
- Console.WriteLine("6 - Exit")
- Dim choice As Integer = Console.ReadLine
- If choice = 1 Then
- addform()
- End If
- If choice = 2 Then
- Loginform()
- End If
- If choice = 3 Then
- deleteform()
- End If
- If choice = 4 Then
- editform()
- End If
- If choice = 6 Then
- Exit Sub
- End If
- Loop
- End Sub
- Function GetHash(theInput As String) As String
- Using hasher As MD5 = MD5.Create() ' create hash object
- ' Convert to byte array and get hash
- Dim dbytes As Byte() =
- hasher.ComputeHash(Encoding.UTF8.GetBytes(theInput))
- ' sb to create string from bytes
- Dim sBuilder As New StringBuilder()
- ' convert byte data to hex string
- For n As Integer = 0 To dbytes.Length - 1
- sBuilder.Append(dbytes(n).ToString("X2"))
- Next n
- Return sBuilder.ToString()
- End Using
- End Function
- Sub LoginUser()
- Console.WriteLine("Enter username: ")
- Dim searchCriteria As String = Console.ReadLine
- Console.WriteLine("Enter Password: ")
- Dim searchcriteria2 As String = Console.ReadLine
- For i = 0 To userdb.Length - 1
- If userdb(i).password = searchcriteria2 And userdb(i).username = searchCriteria Then
- Console.WriteLine(userdb(i).id.ToString + ": " + userdb(i).username)
- End If
- Next
- Console.WriteLine("Which user: ")
- activeUser = userdb(Console.ReadLine())
- For i = 0 To userdb.Length - 1
- Next
- End Sub
- Sub Loginform()
- Console.WriteLine("Enter username: ")
- Dim searchCriteria As String = Console.ReadLine
- Console.WriteLine("Enter Password: ")
- Dim searchcriteria2 As String = Console.ReadLine
- For i = 0 To userdb.Length - 1
- If formdb(i).password = searchcriteria2 And formdb(i).name = searchCriteria Then
- Console.WriteLine(formdb(i).id.ToString + ": " + formdb(i).name)
- End If
- Next
- Console.WriteLine("Which user: ")
- formuser = formdb(Console.ReadLine())
- For i = 0 To formdb.Length - 1
- Next
- End Sub
- Sub deleteuser()
- userdb(activeUser.id) = Nothing
- activeUser = Nothing
- writefileuser()
- End Sub
- Sub deleteform()
- formdb(formuser.id) = Nothing
- formuser = Nothing
- writefileform()
- End Sub
- Sub edituser()
- Console.WriteLine("1: " + activeUser.username)
- Console.WriteLine("2: " + activeUser.password)
- Console.WriteLine("3: " + activeUser.fname)
- Console.WriteLine("4: " + activeUser.sname)
- Console.WriteLine("5: " + activeUser.form)
- Console.WriteLine("6: " + activeUser.age.ToString)
- Console.WriteLine("7: " + activeUser.points.ToString)
- Console.WriteLine("8: spend points")
- Dim choice As Integer = Console.ReadLine
- If choice = 1 Then
- activeUser.username = Console.ReadLine
- End If
- If choice = 2 Then
- activeUser.password = Console.ReadLine
- End If
- If choice = 3 Then
- activeUser.fname = Console.ReadLine
- End If
- If choice = 4 Then
- activeUser.sname = Console.ReadLine
- End If
- If choice = 5 Then
- activeUser.form = Console.ReadLine
- End If
- If choice = 6 Then
- activeUser.age = Console.ReadLine
- End If
- If choice = 8 Then
- End If
- userdb(activeUser.id) = activeUser
- writefileuser()
- End Sub
- Sub editform()
- Console.WriteLine("1: " + formuser.name)
- Console.WriteLine("2: " + formuser.teacher)
- Console.WriteLine("3: " + formuser.year.ToString)
- Console.WriteLine("4: Award points to a student")
- Dim choice As Integer = Console.ReadLine
- If choice = 1 Then
- formuser.name = Console.ReadLine
- End If
- If choice = 2 Then
- formuser.teacher = Console.ReadLine
- End If
- If choice = 3 Then
- formuser.year = Console.ReadLine
- End If
- If choice = 4 Then
- Console.WriteLine("Enter Username: ")
- Dim searchCriteria As String = Console.ReadLine
- For i = 0 To userdb.Length - 1
- If userdb(i).username = searchCriteria Then
- Console.WriteLine("How many points? ")
- Dim points As Integer = Console.ReadLine
- activeUser.points = points
- End If
- Next
- End If
- End Sub
- Sub adduser()
- AddUser("ID: ", activeUser.id)
- AddUser("Username: ", activeUser.username)
- AddUser("Password: ", activeUser.password)
- activeUser.password = GetHash(activeUser.password)
- AddUser("First name: ", activeUser.fname)
- AddUser("Surname: ", activeUser.sname)
- For i = 0 To formdb.Length - 1
- If formdb(i).name <> Nothing Then
- Console.WriteLine(formdb(i).id.ToString + " " + formdb(i).name)
- End If
- Next
- Console.WriteLine("Which form?")
- activeUser.form = formdb(Console.ReadLine).name
- AddUser("Age: ", activeUser.age)
- userdb(activeUser.id) = activeUser
- writefileuser()
- End Sub
- Sub addform()
- Addform("ID: ", formuser.id)
- Addform("name: ", formuser.name)
- Addform("teacher: ", formuser.teacher)
- Addform("year: ", formuser.year)
- Addform("Password: ", formuser.password)
- formdb(formuser.id) = formuser
- writefileform()
- End Sub
- Sub readfileuser()
- Dim filetext As String = My.Computer.FileSystem.ReadAllText("user.txt")
- Dim record() As String = filetext.Split(";")
- For i = 0 To record.Length - 1
- Dim field() As String = record(i).Split(",")
- If field(0) <> Nothing Then
- activeUser.id = field(0)
- activeUser.username = field(1)
- activeUser.password = field(2)
- activeUser.fname = field(3)
- activeUser.sname = field(4)
- activeUser.form = field(5)
- activeUser.age = field(6)
- userdb(activeUser.id) = activeUser
- End If
- Next
- End Sub
- Sub readfileform()
- Dim filetext As String = My.Computer.FileSystem.ReadAllText("form.txt")
- Dim record() As String = filetext.Split(";")
- For i = 0 To record.Length - 1
- Dim field() As String = record(i).Split(",")
- If field(0) <> Nothing Then
- formuser.id = field(0)
- formuser.name = field(1)
- formuser.teacher = field(2)
- formuser.year = field(3)
- formdb(formuser.id) = formuser
- End If
- Next
- End Sub
- Sub writefileuser()
- Dim filetext As String
- For i = 0 To userdb.Length - 1
- filetext = filetext + userdb(i).id.ToString
- filetext = filetext + "," + userdb(i).username
- filetext = filetext + "," + userdb(i).password
- filetext = filetext + "," + userdb(i).fname
- filetext = filetext + "," + userdb(i).sname
- filetext = filetext + "," + userdb(i).form
- filetext = filetext + "," + userdb(i).age.ToString + ";"
- Next
- My.Computer.FileSystem.WriteAllText("user.txt", filetext, False)
- End Sub
- Sub writefileform()
- Dim filetext As String
- For i = 0 To userdb.Length - 1
- filetext = filetext + formdb(i).id.ToString
- filetext = filetext + "," + formdb(i).name
- filetext = filetext + "," + formdb(i).teacher
- filetext = filetext + "," + formdb(i).year.ToString + ";"
- Next
- My.Computer.FileSystem.WriteAllText("form.txt", filetext, False)
- End Sub
- Sub AddUser(ByVal text As String, ByRef variable As String)
- Do
- Try
- Console.Write(text)
- variable = Console.ReadLine
- Exit Do
- Catch ex As Exception
- Console.WriteLine("Error: Please try again")
- End Try
- Loop
- End Sub
- Sub AddUser(ByVal text As String, ByRef variable As Integer)
- Do
- Try
- Console.Write(text)
- variable = Console.ReadLine
- Exit Do
- Catch ex As Exception
- Console.WriteLine("Error: Please try again")
- End Try
- Loop
- End Sub
- Sub Addform(ByVal text As String, ByRef variable As String)
- Do
- Try
- Console.Write(text)
- variable = Console.ReadLine
- Exit Do
- Catch ex As Exception
- Console.WriteLine("Error: Please try again")
- End Try
- Loop
- End Sub
- Sub Addform(ByVal text As String, ByRef variable As Integer)
- Do
- Try
- Console.Write(text)
- variable = Console.ReadLine
- Exit Do
- Catch ex As Exception
- Console.WriteLine("Error: Please try again")
- End Try
- Loop
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement