Guest User

Untitled

a guest
Jan 19th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. protected void logInButton_Click(object sender, EventArgs e)
  2. {
  3. Session["User"] = logUsernameTextBox.Text;
  4. bool successfulLogin = false;
  5.  
  6. string userFilePath = Server.MapPath("~") + "/App_Data/userFile.txt";
  7. string[] userArray = File.ReadAllLines(Server.MapPath("~") + "/App_Data/userFile.txt");
  8.  
  9.  
  10. for (int i = 0; i < userArray.Length; i++)
  11. {
  12. //Split username password
  13. string[] userPasswordPair = userArray[i].Split(' ');
  14.  
  15.  
  16. //if username and password given match any user pair
  17.  
  18. if (userPasswordPair[0] == logUsernameTextBox.Text && userPasswordPair[1] == logPasswordTextBox.Text)
  19. {
  20. successfulLogin = true;
  21. }
  22.  
  23. }
  24. // if the username and password match a set in the file then successful login
  25. if (successfulLogin == true)
  26. {
  27. Response.Write("Successful Login");
  28. Session["User"] = logUsernameTextBox.Text;
  29. Response.Redirect("TuitterDisplay.aspx");
  30. }
  31. //if username and password did not match set
  32. else if (successfulLogin == false)
  33. {
  34. Response.Write("Unsuccessful Login");
  35. logErrorLabel.Text = ("Unsuccessful Login");
  36. }
  37. }
  38. protected void signUpButton_Click(object sender, EventArgs e)
  39. {
  40.  
  41. bool successfulLogin = false;
  42.  
  43. string userFilePath = Server.MapPath("~") + "/App_Data/userFile.txt";
  44. string[] userArray = File.ReadAllLines(Server.MapPath("~") + "/App_Data/userFile.txt");
  45.  
  46.  
  47. for (int i = 0; i < userArray.Length; i++)
  48. {
  49. //Split username password
  50. string[] userPasswordPair = userArray[i].Split(' ');
  51.  
  52.  
  53. //if username and password given match any user pair
  54.  
  55. if (userPasswordPair[0] == newUsernameTextBox.Text)
  56. {
  57. successfulLogin = true;
  58. break;
  59. }
  60.  
  61. }
  62. // if the username and password match a set in the file then successful login
  63. if (successfulLogin == true)
  64. {
  65. signErrorLabel.Text = "User Exists";
  66.  
  67. }
  68. //if username and password did not match set
  69. else if (successfulLogin == false)
  70. {
  71. using (StreamWriter logfile = File.AppendText(userFilePath))
  72. {
  73. logfile.WriteLine(newUsernameTextBox.Text + " " + newPasswordTextBox.Text);
  74. logfile.Close();
  75. }
  76. Session["User"] = newUsernameTextBox.Text;
  77. Response.Redirect("TuitterDisplay.aspx");
  78. }
  79. }
  80. }
Add Comment
Please, Sign In to add comment