protected void btnDecrypt_Click(object sender, EventArgs e)
 {
     string input = txtEncryptDecrypt.Text;
     if (input != "")
     {
         AllServices.ServiceSOAPClient myProxy = new AllServices.ServiceSOAPClient("SOAPEndpoint");
         string result = myProxy.Decrypt(input);
         myProxy.Close();
         txtEncryptDecrypt.Text = result;
     }
     else
     {
         txtEncryptDecrypt.Text = "Error: Invalid Input";
     }
 }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        // Invalidate any current login.
        Session["name"] = null;
        Session["username"] = null;
        Session["admin"] = null;
        Session["staff"] = null;

        string membersPath = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, @"App_Data\Members.xml");

        XmlDocument membersDoc = new XmlDocument();

        try
        {
            membersDoc.Load(membersPath);
        }
        catch (Exception ex)
        {
            return;
        }

        string username = txtUsername.Text;
        string password = txtPassword.Text;

        AllServices.ServiceSOAPClient myProxy = new AllServices.ServiceSOAPClient("SOAPEndpoint");
        string encryptedUsername = myProxy.Encrypt(username);
        string encryptedPassword = myProxy.Encrypt(password);
        myProxy.Close();

        XmlNodeList members = membersDoc.SelectNodes("Members/Member");

        // Check if member exists and password is valid.

        Boolean exists = false;
        for (int i = 0; i < members.Count; i++)
        {
            string user = members[i].ChildNodes.Item(1).InnerText;
            if (user.Equals(encryptedUsername))
            {
                exists = true;

                if (members[i].ChildNodes.Item(2).InnerText == encryptedPassword)
                {
                    /* PERFORM LOGIN STUFF HERE. USERNAME AND PASSWORD MATCHES. */
                    myProxy = new AllServices.ServiceSOAPClient("SOAPEndpoint");
                    string name = myProxy.Decrypt(members[i].ChildNodes.Item(0).InnerText);

                    Session["name"] = (object) name;
                    Session["username"] = (object) username;

                    // Load staff XML and see if user is staff member.

                    string staffPath = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, @"App_Data\Staff.xml");

                    XmlDocument staffDoc = new XmlDocument();

                    try
                    {
                        staffDoc.Load(staffPath);
                    }
                    catch (Exception ex)
                    {
                        return;
                    }
                    XmlNodeList staff = staffDoc.SelectNodes("Staff/Member");

                    for (int j = 0; j < staff.Count; j++)
                    {
                        if (staff[j].ChildNodes.Item(0).InnerText.Equals(encryptedUsername))
                        {
                            if (staff[j].ChildNodes.Item(1).InnerText == "true")
                            {
                                Session["admin"] = (object) true;
                            }
                            if (staff[j].ChildNodes.Item(2).InnerText == "true")
                            {
                                Session["staff"] = (object) true;
                            }
                            break;
                        }
                    }

                    Update();

                    statusMessage.Text = "Successful Login!";

                    Server.Transfer("~/Members/Members.aspx");
                }
                else
                {
                    statusMessage.Text = "Error: Password incorrect.";
                }

                break;
            }
        }

        if (!exists)
        {
            statusMessage.Text = "Error: Username does not exist.";
        }
    }