Advertisement
Guest User

Untitled

a guest
Feb 10th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. Imports System
  2. Imports System.IO
  3. Public Class Form1
  4. Dim password, username, newpass, newuser As String
  5. Dim valid As Boolean = False
  6. Dim fileread As String
  7. Structure passwordRec
  8. Dim RecUname As String
  9. Dim RecPword As String
  10. End Structure
  11. Dim SingleRec As passwordRec
  12.  
  13. Sub checkvalid()
  14. 'read in password
  15. password = txtPassword.Text
  16. 'read in username
  17. username = txtUsername.Text
  18. 'open file
  19. FileOpen(1, CurDir() & "/user.txt", OpenMode.Input)
  20. 'read from file
  21. While Not EOF(1)
  22. Input(1, SingleRec.RecUname)
  23. Input(1, SingleRec.RecPword)
  24. 'checking credentials against the record
  25. If username = SingleRec.RecUname And password = SingleRec.RecPword Then
  26. valid = True
  27. End If
  28. If valid Then
  29. MsgBox("Correct")
  30. Me.Close()
  31. Else
  32. MsgBox("Incorrect")
  33. Me.Close()
  34. End If
  35. End While
  36. FileClose(1)
  37. End Sub
  38. Function register(user, pass) As String
  39. FileOpen(1, CurDir() & "/user.txt", OpenMode.Append)
  40. ' user.replace("""", "")
  41. ' pass.replace("""", "")
  42. WriteLine(1, user, pass)
  43. FileClose(1)
  44. End Function
  45. Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  46.  
  47. End Sub
  48.  
  49. Private Sub btnLogin_Click(sender As System.Object, e As System.EventArgs) Handles btnLogin.Click
  50. checkvalid()
  51. End Sub
  52.  
  53. Private Sub btnRegister_Click(sender As System.Object, e As System.EventArgs) Handles btnRegister.Click
  54. newuser = InputBox("Enter username")
  55. newpass = InputBox("Enter password")
  56. register(newuser, newpass)
  57. End Sub
  58. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement