protected void btnAuthenticateUser_Click(object sender, EventArgs e) { String password = txtPassword.Text; String username = txtUsername.Text; UserXmlManipulation obj = new UserXmlManipulation(); lblAuthMsg.Visible = false; int memberFlag = 1; if (obj.AuthenticateUserCredential(username, password, memberFlag)) { lblAuthMsg.Visible = true; lblAuthMsg.Text = "Authentication Successful!!"; } else { lblAuthMsg.Visible = true; lblAuthMsg.Text = "Authentication Failed !!!"; } }
protected void ButtonLogin_Click(object sender, EventArgs e) { string userName = loginControl.UserName; string password = loginControl.Password; if (userName.Equals("") || password.Equals("")) { LabelLoginError.Visible = true; LabelLoginError.Text = "Please enter username & password"; } else { UserXmlManipulation staffXml = new UserXmlManipulation(); bool isValidUser = staffXml.AuthenticateUserCredential(userName, password, STAFF_XML); if (isValidUser) { // storing the user information in the session for future use GeneralUserClass staff = new GeneralUserClass(); staff.username = userName; Session["StaffAccount"] = staff; // storing username in a cookie if user checks the checkbox at UI if (CheckBoxSaveUsername.Checked == true) { HttpCookie myCookies = new HttpCookie("staffLoginCookie"); myCookies["UserName"] = loginControl.UserName; myCookies.Expires = DateTime.Now.AddMinutes(5); Response.Cookies.Add(myCookies); } Response.Redirect("~/Staff.aspx"); } else { LabelCookie.Visible = true; LabelCookie.Text = "Wrong username/password entered..!"; } } }