internal static UserContext Authenticate(string UserName, string Password) { // Change History // // Date Edit Author Comment // -----------+-------+-------+--------------------------------------------- // 02-Feb-12 [100] SSN Created // -----------+-------+-------+--------------------------------------------- UserContext userInfo = new UserContext(); userInfo.Authenticated = false; if (UserName.Trim() != "" && Password.Trim() != "") { try { SqlConnection con = new SqlConnection(); con.ConnectionString = GetConnectionString(UserName, Password); con.Open(); if (con.State == ConnectionState.Open) { using (SqlCommand cmd = con.CreateCommand()) { //cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "select users_refno from users where username='******' and password='******'"; using (SqlDataReader dr = cmd.ExecuteReader()) { if (dr.HasRows) { // return userInfo; dr.Read(); userInfo.Authenticated = true; userInfo.userName = UserName; userInfo.UserRefno = ((int)dr.GetValue(dr.GetOrdinal("users_REFNO"))); } } } } con.Close(); } catch (Exception ex) { userInfo.Authenticated = false; } } else { userInfo.Authenticated = false; } return userInfo; }
//protected void Button1_Click(object sender, EventArgs e) //{ // UserContext uInfo = new UserContext(); // int maxQues; // uInfo = Common.Authenticate(TextBox1.Text, TextBox2.Text); // if(uInfo.Authenticated) // { // maxQues =Convert.ToInt32(ConfigurationManager.AppSettings["MaxQues"]); // //TextBox1.Text = ""; // //TextBox1.Text = "Success"; // Session["Username"] = TextBox1.Text; // Session["UserRefno"] = uInfo.UserRefno; // Session["MaxQues"] = maxQues; // Response.Redirect("Questions.aspx"); // } // else // { // TextBox1.Text = "Failure"; // } //} protected void LoginButton_Click(object sender, EventArgs e) { UserContext uInfo = new UserContext(); // int maxQues; uInfo = Common.Authenticate(UserName.Text.ToUpper(), Password.Text); if (uInfo.Authenticated) { //TextBox1.Text = ""; //TextBox1.Text = "Success"; Session["Username"] = UserName.Text; Session["UserRefno"] = uInfo.UserRefno; // Session["MaxQues"] = maxQues; Response.Redirect("SelectEvent.aspx"); } else { Label1.Visible = true; Label1.Text = "Username or Password is incorrect. Please try again!"; Password.Text = ""; } }