protected void ButtonRegister_Click(object sender, EventArgs e) { string userName = TextBoxUsername.Text; string email = TextBoxEmail.Text; string password = TextBoxPassword.Text; string confirmPassword = TextBoxConfirmPassword.Text; if (userName.Equals("") || password.Equals("'") || confirmPassword.Equals("")) { LabelErrorMessage.Visible = true; LabelErrorMessage.Text = "Please enter the required fields marked with asterisk(*)"; } else if (!password.Equals(confirmPassword)) { LabelErrorMessage.Visible = true; LabelErrorMessage.Text = "Password mismatch..Please try again"; } else { UserXmlManipulation memberXml = new UserXmlManipulation(); bool isMemberAdded = memberXml.addUserCredential(userName, password, MEMBER_XML); if (isMemberAdded) { LabelUserAdded.Visible = true; LabelUserAdded.Text = userName + " Added Successfully"; } else { LabelErrorMessage.Visible = true; LabelErrorMessage.Text = "User already exists or an error at backend"; } } }
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 btnAdd_Click(object sender, EventArgs e) { String password = txtPassword.Text; String username = txtUsername.Text; lblAddUserMsg.Visible = false; int memberFlag = 1; UserXmlManipulation obj = new UserXmlManipulation(); if (obj.addUserCredential(username, password, memberFlag)) { lblAddUserMsg.Visible = true; lblAddUserMsg.Text = "Successfully Added!!"; } else { lblAddUserMsg.Visible = true; lblAddUserMsg.Text = "Unable to Add" + txtUsername.Text + "!!! Try Again"; } }
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..!"; } } }