protected void LoginFunc(object sender, EventArgs e)
        {
            XDocument xPlatformXml = XDocument.Load(HttpContext.Current.Server.MapPath("../page4/Staff.xml"));
            string    enc_psw      = Enc_dec.Encrypt(Password.Text);
            string    id           = UserName.Text;
            string    output       = "";

            XElement xel = xPlatformXml.Element("AccRoot")
                           .Elements("account")
                           .Where(x => x.Element("name").Value == id)
                           .Where(x => x.Element("password").Value == enc_psw)
                           .SingleOrDefault();

            if (xel != null)
            {
                output = "true";
                if (Session["member_username"] != null)
                {
                    Session.Clear();
                    if (Request.Cookies["member_login"] != null)
                    {
                        Request.Cookies["member_login"].Expires = DateTime.Now.AddDays(-1d);
                    }
                }
                Session["staff_username"] = UserName.Text;
                Response.Redirect("Staff_page.aspx");
            }
            else
            {
                output = "Wrong username or password!s";
            }

            Output.Text = output;
        }
예제 #2
0
        protected void LoginFunc(object sender, EventArgs e)
        {
            XDocument xPlatformXml = XDocument.Load(HttpContext.Current.Server.MapPath("../page4/members.xml"));
            string    enc_psw      = Enc_dec.Encrypt(Password.Text);
            string    id           = UserName.Text;
            string    output       = "";

            XElement xel = xPlatformXml.Element("AccRoot")
                           .Elements("account")
                           .Where(x => x.Element("email").Value == id)
                           .Where(x => x.Element("password").Value == enc_psw)
                           .SingleOrDefault();

            if (xel != null)
            {
                output = "Login Successful";
                if (Session["staff_username"] != null)
                {
                    Session.Clear();
                }
                Session["member_username"] = UserName.Text;
                if (Persistent.Checked)
                {
                    HttpCookie mycookie = new HttpCookie("member_login");
                    mycookie["username"] = UserName.Text;
                    mycookie.Expires     = DateTime.Now.AddMonths(6);
                    Response.Cookies.Add(mycookie);
                }


                Response.Redirect("Member_page.aspx");
            }
            else
            {
                output = "Wrong username or password!s";
            }

            Output.Text = output;
        }
        protected void submit_Click(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                Label2.Text = control.outputz;
            }


            string username = UserName.Text;
            string enc_psw  = Enc_dec.Encrypt(Password.Text);
            string email    = Email.Text;

            if ((Label2.Text) == ("Verified."))
            {
                string fileName = HttpContext.Current.Server.MapPath("../page4/members.xml");

                //If the file does not exist then create a new xml file
                if (!File.Exists(fileName))
                {
                    XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
                    xmlWriterSettings.Indent = true;
                    xmlWriterSettings.NewLineOnAttributes = true;
                    using (XmlWriter xmlWriter = XmlWriter.Create(fileName, xmlWriterSettings))
                    {
                        xmlWriter.WriteStartDocument();
                        xmlWriter.WriteStartElement("AccRoot");
                        xmlWriter.WriteStartElement("account");

                        xmlWriter.WriteElementString("name", username);
                        xmlWriter.WriteElementString("email", email);
                        xmlWriter.WriteElementString("password", enc_psw);


                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndElement();
                        xmlWriter.WriteEndDocument();
                        xmlWriter.Flush();
                        xmlWriter.Close();
                    }
                    Response.Redirect("Member_login.aspx");
                    Output.Text = "Account created."; //Account created Sucessfully
                }
                //Else check if the file contains the user already based on email and insert into the xml file if it doesnt exist.
                else
                {
                    int flag = 0;

                    XDocument xPlatformXml = XDocument.Load(HttpContext.Current.Server.MapPath("../page4/members.xml"));

                    XElement xel = xPlatformXml.Element("AccRoot")
                                   .Elements("account")
                                   .Where(x => x.Element("email").Value == email)
                                   .SingleOrDefault();
                    if (xel != null)
                    {
                        flag = 1;
                    }

                    if (flag == 1)
                    {
                        Output.Text = "Account already exists.";   //Account already exists
                    }
                    else
                    {
                        XDocument xDocument = XDocument.Load(HttpContext.Current.Server.MapPath("../page4/members.xml"));
                        XElement  accRoot   = xDocument.Root;
                        accRoot.Add(new XElement("account",
                                                 new XElement("name", username),
                                                 new XElement("email", email),
                                                 new XElement("password", enc_psw)
                                                 ));
                        xDocument.Save(HttpContext.Current.Server.MapPath("../page4/members.xml"));

                        Response.Redirect("Member_login.aspx");
                        Output.Text = "Account created."; //Account created successfully
                    }
                }
            }
            else
            {
                Output.Text = "Captcha not verified.";
            }
        }