Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void logInButton_Click(object sender, EventArgs e)
- {
- Session["User"] = logUsernameTextBox.Text;
- bool successfulLogin = false;
- string userFilePath = Server.MapPath("~") + "/App_Data/userFile.txt";
- string[] userArray = File.ReadAllLines(Server.MapPath("~") + "/App_Data/userFile.txt");
- for (int i = 0; i < userArray.Length; i++)
- {
- //Split username password
- string[] userPasswordPair = userArray[i].Split(' ');
- //if username and password given match any user pair
- if (userPasswordPair[0] == logUsernameTextBox.Text && userPasswordPair[1] == logPasswordTextBox.Text)
- {
- successfulLogin = true;
- }
- }
- // if the username and password match a set in the file then successful login
- if (successfulLogin == true)
- {
- Response.Write("Successful Login");
- Session["User"] = logUsernameTextBox.Text;
- Response.Redirect("TuitterDisplay.aspx");
- }
- //if username and password did not match set
- else if (successfulLogin == false)
- {
- Response.Write("Unsuccessful Login");
- logErrorLabel.Text = ("Unsuccessful Login");
- }
- }
- protected void signUpButton_Click(object sender, EventArgs e)
- {
- bool successfulLogin = false;
- string userFilePath = Server.MapPath("~") + "/App_Data/userFile.txt";
- string[] userArray = File.ReadAllLines(Server.MapPath("~") + "/App_Data/userFile.txt");
- for (int i = 0; i < userArray.Length; i++)
- {
- //Split username password
- string[] userPasswordPair = userArray[i].Split(' ');
- //if username and password given match any user pair
- if (userPasswordPair[0] == newUsernameTextBox.Text)
- {
- successfulLogin = true;
- break;
- }
- }
- // if the username and password match a set in the file then successful login
- if (successfulLogin == true)
- {
- signErrorLabel.Text = "User Exists";
- }
- //if username and password did not match set
- else if (successfulLogin == false)
- {
- using (StreamWriter logfile = File.AppendText(userFilePath))
- {
- logfile.WriteLine(newUsernameTextBox.Text + " " + newPasswordTextBox.Text);
- logfile.Close();
- }
- Session["User"] = newUsernameTextBox.Text;
- Response.Redirect("TuitterDisplay.aspx");
- }
- }
- }
Add Comment
Please, Sign In to add comment