Need help with the code Im working with. The code reads from a text file which contains username and password (e.g. mike mike123) and should match the username "mike" to password "mike123" and redirect the user to another webpage. At the moment, my code only shows the Invalid error dialog box. The .Split(' ') method separates username and password into array of 0 and 1. DO I need some kind of while loop?
protected void loginButton_Click(object sender, ImageClickEventArgs e) { // location of the files with login details and tuits string userFilePath = Server.MapPath("~") + "/App_Data/tuitterUsers.txt"; string tuitFilePath = Server.MapPath("~") + "/App_Data/tuitterMessages.txt"; //creating session for password Session["UserID"] = usernameTB.Text; Session["Password"] = passwordTB.Text; string[] readText = File.ReadAllLines(userFilePath); string[] userPassswordPair = userFilePath.Split(' '); foreach (string s in readText) { if (usernameTB.Text == s[0].ToString() && passwordTB.Text == s[1].ToString()) { Response.Redirect("TuitterMain.aspx"); } else ScriptManager.RegisterStartupScript(this, GetType(), "Success", "alert('Invalid username/password');", true); } }