Advertisement
Guest User

code for douggie cause he cant do it himself

a guest
Mar 9th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.23 KB | None | 0 0
  1. Imports System
  2. Imports System.Security.Cryptography
  3. Imports System.Text
  4.  
  5. Module Module1
  6.  
  7. Structure formBlueprint
  8. Dim id As Integer
  9. Dim name As String
  10. Dim teacher As String
  11. Dim year As Integer
  12. Dim password As String
  13.  
  14. End Structure
  15. Structure userblueprint
  16. Dim id As Integer
  17. Dim username As String
  18. Dim password As String
  19. Dim fname As String
  20. Dim sname As String
  21. Dim form As String
  22. Dim age As Integer
  23. Dim points As Integer
  24. End Structure
  25. Dim activeUser As userblueprint
  26. Dim userdb(100) As userblueprint
  27. Dim formuser As formBlueprint
  28. Dim formdb(100) As formBlueprint
  29.  
  30.  
  31. Sub main()
  32. readfileuser()
  33. readfileform()
  34. Do
  35. Console.Clear()
  36. Console.WriteLine("Teacher - 1")
  37. Console.WriteLine("Student - 2")
  38.  
  39.  
  40. Dim choice As Integer = Console.ReadLine
  41. If choice = 1 Then
  42. formMenu()
  43. End If
  44. If choice = 2 Then
  45. usermenu()
  46. End If
  47.  
  48.  
  49.  
  50. Loop
  51.  
  52. End Sub
  53. Sub pointarea()
  54. Console.WriteLine("1 - Check points:")
  55. Console.WriteLine("2 - spend points")
  56. End Sub
  57. Sub usermenu()
  58. readfileuser()
  59. activeUser = Nothing
  60. Do
  61. Console.Clear()
  62. Console.WriteLine("1 - Add User")
  63. Console.WriteLine("2 - Login")
  64. If activeUser.username <> Nothing Then
  65. Console.WriteLine("3 - Delete " + activeUser.username)
  66. Console.WriteLine("4 - Edit, check points and spend points " + activeUser.username)
  67. End If
  68. Console.WriteLine("5 - Exit")
  69. Dim choice As Integer = Console.ReadLine
  70. If choice = 1 Then
  71. adduser()
  72. End If
  73. If choice = 2 Then
  74. LoginUser()
  75. End If
  76. If choice = 3 Then
  77. deleteuser()
  78. End If
  79. If choice = 4 Then
  80. edituser()
  81. End If
  82. If choice = 5 Then
  83. Exit Sub
  84. End If
  85. Loop
  86. End Sub
  87. Sub formMenu()
  88. readfileform()
  89. formuser = Nothing
  90. Do
  91. Console.Clear()
  92. Console.WriteLine("1 - Add form")
  93. Console.WriteLine("2 - Login")
  94. If formuser.name <> Nothing Then
  95. Console.WriteLine("3 - Delete form " + formuser.name)
  96. Console.WriteLine("4 - Edit form and add points to students " + formuser.name)
  97.  
  98. End If
  99. Console.WriteLine("6 - Exit")
  100. Dim choice As Integer = Console.ReadLine
  101. If choice = 1 Then
  102. addform()
  103. End If
  104. If choice = 2 Then
  105. Loginform()
  106. End If
  107. If choice = 3 Then
  108. deleteform()
  109. End If
  110. If choice = 4 Then
  111. editform()
  112. End If
  113.  
  114.  
  115.  
  116. If choice = 6 Then
  117. Exit Sub
  118. End If
  119. Loop
  120. End Sub
  121. Function GetHash(theInput As String) As String
  122. Using hasher As MD5 = MD5.Create() ' create hash object
  123. ' Convert to byte array and get hash
  124. Dim dbytes As Byte() =
  125. hasher.ComputeHash(Encoding.UTF8.GetBytes(theInput))
  126. ' sb to create string from bytes
  127. Dim sBuilder As New StringBuilder()
  128. ' convert byte data to hex string
  129. For n As Integer = 0 To dbytes.Length - 1
  130. sBuilder.Append(dbytes(n).ToString("X2"))
  131. Next n
  132. Return sBuilder.ToString()
  133. End Using
  134. End Function
  135.  
  136. Sub LoginUser()
  137. Console.WriteLine("Enter username: ")
  138.  
  139. Dim searchCriteria As String = Console.ReadLine
  140. Console.WriteLine("Enter Password: ")
  141.  
  142. Dim searchcriteria2 As String = Console.ReadLine
  143. For i = 0 To userdb.Length - 1
  144. If userdb(i).password = searchcriteria2 And userdb(i).username = searchCriteria Then
  145. Console.WriteLine(userdb(i).id.ToString + ": " + userdb(i).username)
  146. End If
  147.  
  148. Next
  149. Console.WriteLine("Which user: ")
  150. activeUser = userdb(Console.ReadLine())
  151. For i = 0 To userdb.Length - 1
  152.  
  153. Next
  154. End Sub
  155. Sub Loginform()
  156. Console.WriteLine("Enter username: ")
  157.  
  158. Dim searchCriteria As String = Console.ReadLine
  159. Console.WriteLine("Enter Password: ")
  160.  
  161. Dim searchcriteria2 As String = Console.ReadLine
  162. For i = 0 To userdb.Length - 1
  163. If formdb(i).password = searchcriteria2 And formdb(i).name = searchCriteria Then
  164. Console.WriteLine(formdb(i).id.ToString + ": " + formdb(i).name)
  165. End If
  166.  
  167. Next
  168. Console.WriteLine("Which user: ")
  169. formuser = formdb(Console.ReadLine())
  170. For i = 0 To formdb.Length - 1
  171.  
  172. Next
  173. End Sub
  174. Sub deleteuser()
  175. userdb(activeUser.id) = Nothing
  176. activeUser = Nothing
  177. writefileuser()
  178. End Sub
  179. Sub deleteform()
  180. formdb(formuser.id) = Nothing
  181. formuser = Nothing
  182. writefileform()
  183. End Sub
  184. Sub edituser()
  185. Console.WriteLine("1: " + activeUser.username)
  186. Console.WriteLine("2: " + activeUser.password)
  187. Console.WriteLine("3: " + activeUser.fname)
  188. Console.WriteLine("4: " + activeUser.sname)
  189. Console.WriteLine("5: " + activeUser.form)
  190. Console.WriteLine("6: " + activeUser.age.ToString)
  191. Console.WriteLine("7: " + activeUser.points.ToString)
  192. Console.WriteLine("8: spend points")
  193. Dim choice As Integer = Console.ReadLine
  194. If choice = 1 Then
  195. activeUser.username = Console.ReadLine
  196. End If
  197. If choice = 2 Then
  198. activeUser.password = Console.ReadLine
  199. End If
  200. If choice = 3 Then
  201. activeUser.fname = Console.ReadLine
  202. End If
  203. If choice = 4 Then
  204. activeUser.sname = Console.ReadLine
  205. End If
  206. If choice = 5 Then
  207. activeUser.form = Console.ReadLine
  208. End If
  209. If choice = 6 Then
  210. activeUser.age = Console.ReadLine
  211. End If
  212. If choice = 8 Then
  213.  
  214. End If
  215. userdb(activeUser.id) = activeUser
  216. writefileuser()
  217. End Sub
  218.  
  219. Sub editform()
  220. Console.WriteLine("1: " + formuser.name)
  221. Console.WriteLine("2: " + formuser.teacher)
  222. Console.WriteLine("3: " + formuser.year.ToString)
  223. Console.WriteLine("4: Award points to a student")
  224.  
  225. Dim choice As Integer = Console.ReadLine
  226. If choice = 1 Then
  227. formuser.name = Console.ReadLine
  228. End If
  229. If choice = 2 Then
  230. formuser.teacher = Console.ReadLine
  231. End If
  232. If choice = 3 Then
  233. formuser.year = Console.ReadLine
  234. End If
  235. If choice = 4 Then
  236. Console.WriteLine("Enter Username: ")
  237. Dim searchCriteria As String = Console.ReadLine
  238. For i = 0 To userdb.Length - 1
  239. If userdb(i).username = searchCriteria Then
  240. Console.WriteLine("How many points? ")
  241. Dim points As Integer = Console.ReadLine
  242. activeUser.points = points
  243. End If
  244. Next
  245. End If
  246.  
  247.  
  248. End Sub
  249.  
  250. Sub adduser()
  251. AddUser("ID: ", activeUser.id)
  252. AddUser("Username: ", activeUser.username)
  253. AddUser("Password: ", activeUser.password)
  254. activeUser.password = GetHash(activeUser.password)
  255. AddUser("First name: ", activeUser.fname)
  256. AddUser("Surname: ", activeUser.sname)
  257.  
  258. For i = 0 To formdb.Length - 1
  259. If formdb(i).name <> Nothing Then
  260. Console.WriteLine(formdb(i).id.ToString + " " + formdb(i).name)
  261. End If
  262. Next
  263.  
  264. Console.WriteLine("Which form?")
  265. activeUser.form = formdb(Console.ReadLine).name
  266.  
  267.  
  268.  
  269.  
  270. AddUser("Age: ", activeUser.age)
  271.  
  272. userdb(activeUser.id) = activeUser
  273. writefileuser()
  274. End Sub
  275. Sub addform()
  276. Addform("ID: ", formuser.id)
  277. Addform("name: ", formuser.name)
  278. Addform("teacher: ", formuser.teacher)
  279. Addform("year: ", formuser.year)
  280. Addform("Password: ", formuser.password)
  281.  
  282. formdb(formuser.id) = formuser
  283. writefileform()
  284. End Sub
  285. Sub readfileuser()
  286. Dim filetext As String = My.Computer.FileSystem.ReadAllText("user.txt")
  287. Dim record() As String = filetext.Split(";")
  288. For i = 0 To record.Length - 1
  289. Dim field() As String = record(i).Split(",")
  290. If field(0) <> Nothing Then
  291. activeUser.id = field(0)
  292. activeUser.username = field(1)
  293. activeUser.password = field(2)
  294. activeUser.fname = field(3)
  295. activeUser.sname = field(4)
  296. activeUser.form = field(5)
  297. activeUser.age = field(6)
  298. userdb(activeUser.id) = activeUser
  299. End If
  300.  
  301. Next
  302. End Sub
  303. Sub readfileform()
  304. Dim filetext As String = My.Computer.FileSystem.ReadAllText("form.txt")
  305. Dim record() As String = filetext.Split(";")
  306. For i = 0 To record.Length - 1
  307. Dim field() As String = record(i).Split(",")
  308. If field(0) <> Nothing Then
  309. formuser.id = field(0)
  310. formuser.name = field(1)
  311. formuser.teacher = field(2)
  312. formuser.year = field(3)
  313.  
  314. formdb(formuser.id) = formuser
  315. End If
  316.  
  317. Next
  318. End Sub
  319. Sub writefileuser()
  320. Dim filetext As String
  321. For i = 0 To userdb.Length - 1
  322. filetext = filetext + userdb(i).id.ToString
  323. filetext = filetext + "," + userdb(i).username
  324. filetext = filetext + "," + userdb(i).password
  325. filetext = filetext + "," + userdb(i).fname
  326. filetext = filetext + "," + userdb(i).sname
  327. filetext = filetext + "," + userdb(i).form
  328. filetext = filetext + "," + userdb(i).age.ToString + ";"
  329. Next
  330. My.Computer.FileSystem.WriteAllText("user.txt", filetext, False)
  331. End Sub
  332.  
  333. Sub writefileform()
  334. Dim filetext As String
  335. For i = 0 To userdb.Length - 1
  336. filetext = filetext + formdb(i).id.ToString
  337. filetext = filetext + "," + formdb(i).name
  338. filetext = filetext + "," + formdb(i).teacher
  339. filetext = filetext + "," + formdb(i).year.ToString + ";"
  340.  
  341. Next
  342. My.Computer.FileSystem.WriteAllText("form.txt", filetext, False)
  343. End Sub
  344. Sub AddUser(ByVal text As String, ByRef variable As String)
  345. Do
  346. Try
  347. Console.Write(text)
  348. variable = Console.ReadLine
  349. Exit Do
  350. Catch ex As Exception
  351. Console.WriteLine("Error: Please try again")
  352. End Try
  353. Loop
  354. End Sub
  355.  
  356. Sub AddUser(ByVal text As String, ByRef variable As Integer)
  357. Do
  358. Try
  359. Console.Write(text)
  360. variable = Console.ReadLine
  361. Exit Do
  362. Catch ex As Exception
  363. Console.WriteLine("Error: Please try again")
  364. End Try
  365. Loop
  366. End Sub
  367. Sub Addform(ByVal text As String, ByRef variable As String)
  368. Do
  369. Try
  370. Console.Write(text)
  371. variable = Console.ReadLine
  372. Exit Do
  373. Catch ex As Exception
  374. Console.WriteLine("Error: Please try again")
  375. End Try
  376. Loop
  377. End Sub
  378. Sub Addform(ByVal text As String, ByRef variable As Integer)
  379. Do
  380. Try
  381. Console.Write(text)
  382. variable = Console.ReadLine
  383. Exit Do
  384. Catch ex As Exception
  385. Console.WriteLine("Error: Please try again")
  386. End Try
  387. Loop
  388. End Sub
  389. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement