コード例 #1
0
        protected void RegisterBtn_Click(object sender, EventArgs e)
        {
            //first make sure passwords match
            if (passwordInput.Value != confirmPasswordInput.Value)
            {
                messageLbl.Text = "Passwords do not match";
                return;
            }
            else
            {
                //init new encryption object using Encryption .dll file
                StringEncryptDecrypt.Encryption encryption = new StringEncryptDecrypt.Encryption();

                //we need to register the username and password within Members.xml
                //get path for Members.xml file
                string path = AppDomain.CurrentDomain.BaseDirectory;
                path += "App_Data\\Members.xml";                 //store to App_Data folder on server?

                //open the Members.xml file
                XDocument doc     = XDocument.Load(path);
                XElement  root    = doc.Element("root");
                XElement  members = root.Element("Members");
                members.Add(new XElement("Member",
                                         new XAttribute("username", usernameInput.Value),
                                         //encrypt the password using StringEncryptDecrypt .dll file
                                         new XAttribute("password", encryption.Encrypt(passwordInput.Value))));
                //save the new member to the xml file
                doc.Save(path);

                //redirect to login page
                Response.Redirect("~/Login.aspx");
            }
        }
コード例 #2
0
 protected void decryptBtn_Click(object sender, EventArgs e)
 {
     //init new encryption object from StringEncryptDecrpy .dll file
     StringEncryptDecrypt.Encryption encryption = new StringEncryptDecrypt.Encryption();
     //decrpyt the string and display it
     decryptedLbl.Text = encryption.Decrypt(decryptStringInput.Value);
 }
コード例 #3
0
        protected bool authenticateUser(string username, string password)
        {
            //init new encryption object using Encryption .dll file
            StringEncryptDecrypt.Encryption encryption = new StringEncryptDecrypt.Encryption();

            //get path for Members.xml file
            string path = AppDomain.CurrentDomain.BaseDirectory;

            path += "App_Data\\Members.xml";             //store to App_Data folder on server?

            //iterate through level 1 elements
            foreach (XElement level1Element in XElement.Load(path).Elements("Members"))
            {
                //iterate through level 2 elements
                foreach (XElement level2Element in level1Element.Elements("Member"))
                {
                    string tempUsername = level2Element.Attribute("username").Value;
                    string tempPassword = encryption.Decrypt(level2Element.Attribute("password").Value);
                    //check each tempUsername/tempPassword against inputted username & password
                    if (username == tempUsername && password == tempPassword)
                    {
                        //both username and password match ->authenticate the user
                        return(true);
                    }
                }
            }

            //no matching username or password found in Members.xml -> do not authenticate the user
            return(false);
        }