Beispiel #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (UserName.Text != null)
            {
                if (Password.Text == ConfirmPassword.Text && Password.Text != null)
                {
                    if (Session["cText"].ToString() == TextBox1.Text)
                    {
                        //add user to XML database
                        //after encryption.

                        EncryptionDecryption encrypter = new EncryptionDecryption();
                        string encrypted_password      = encrypter.Encryption(Password.Text);


                        XmlWriterSettings settings = new XmlWriterSettings();
                        settings.Indent = true;
                        settings.NewLineOnAttributes = true;

                        XmlDocument xref = new XmlDocument();
                        xref.Load(HttpContext.Current.Server.MapPath("App_Data/Member.xml"));

                        XPathNavigator nav = xref.CreateNavigator();

                        nav.MoveToChild("Members", "");
                        XmlWriter writer = nav.AppendChild();

                        writer.WriteStartElement("User");
                        writer.WriteElementString("Username", UserName.Text);
                        writer.WriteElementString("Password", encrypted_password);
                        writer.WriteEndElement();


                        writer.Close();

                        xref.Save(HttpContext.Current.Server.MapPath("App_Data/Member.xml"));



                        Response.Redirect("~/Member.aspx");
                    }
                    else
                    {
                        errorLabel.Visible = true;
                        errorLabel.Text    = "Validation incorrect.";
                    }
                }
                else
                {
                    //show pw do not match
                    errorLabel.Visible = true;
                    errorLabel.Text    = "Passwords Must Match!";
                }
            }
            else
            {
                errorLabel.Visible = true;
                errorLabel.Text    = "Username cannot be blank";
            }
        }
        public ResponseData ResetPassword(int id, ResetPasswordRequest resetPasswordRequest)
        {
            try
            {
                ResponseData responseData = null;

                var    user        = _context.Users.First(userID => userID.ID == id);
                string newPassword = EncryptionDecryption.Encryption(resetPasswordRequest.NewPassword);
                user.Password = newPassword;
                _context.SaveChanges();

                responseData = new ResponseData()
                {
                    ID         = user.ID,
                    FirstName  = user.FirstName,
                    LastName   = user.LastName,
                    ProfilePic = user.ProfilePic,
                    Email      = user.Email
                };
                return(responseData);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public ResponseData UserLogin(LoginRequest login)
        {
            try
            {
                ResponseData responseData      = null;
                string       encryptedPassword = EncryptionDecryption.Encryption(login.Password);
                var          userData          = _context.Users.
                                                 Where(user => user.Email == login.Email && user.Password == encryptedPassword)
                                                 .FirstOrDefault <UserInfo>();

                if (userData != null)
                {
                    responseData = new ResponseData()
                    {
                        ID         = userData.ID,
                        FirstName  = userData.FirstName,
                        LastName   = userData.LastName,
                        ProfilePic = userData.ProfilePic,
                        Email      = userData.Email
                    };
                }
                return(responseData);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Beispiel #4
0
        protected void bttn_encrypt_Click(object sender, EventArgs e)
        {
            EncryptionDecryption myEncrypter = new EncryptionDecryption();
            string result = myEncrypter.Encryption(txt_encrypt.Text);

            lbl_encryptResults.Text = result;
        }
        public ResponseData CreateAccount(SignUpRequest userSignUp)
        {
            try
            {
                string encryptedPassword = EncryptionDecryption.Encryption(userSignUp.Password);

                var checkUsers = _context.Users.
                                 Where(existedUser => existedUser.Email == userSignUp.Email).
                                 FirstOrDefault();
                if (checkUsers == null)
                {
                    UserInfo user = new UserInfo()
                    {
                        FirstName    = userSignUp.FirstName,
                        LastName     = userSignUp.LastName,
                        Email        = userSignUp.Email,
                        Password     = encryptedPassword,
                        CreatedDate  = DateTime.Now,
                        ModifiedDate = DateTime.Now
                    };
                    _context.Users.Add(user);
                    _context.SaveChanges();
                    ResponseData responseData = new ResponseData()
                    {
                        ID         = user.ID,
                        FirstName  = user.FirstName,
                        LastName   = user.LastName,
                        ProfilePic = user.ProfilePic,
                        Email      = user.Email
                    };
                    return(responseData);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Beispiel #6
0
        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            //IF button checked, save info to cookies
            bool auth     = false;
            bool remember = false;

            XmlTextReader reader = new XmlTextReader(HttpContext.Current.Server.MapPath("App_Data/Member.xml"));

            if (reader == null)
            {
                auth = false;
            }
            else
            {
                while (reader.Read())
                {
                    if (reader.Name == "Username")
                    {
                        reader.Read();

                        if (reader.Value.ToString() == Login1.UserName)
                        {
                            while (reader.Read())
                            {
                                if (reader.Name == "Password")
                                {
                                    reader.Read();

                                    //encrypt password to check
                                    EncryptionDecryption encrypter = new EncryptionDecryption();
                                    string pass = encrypter.Encryption(Login1.Password);

                                    if (reader.Value.ToString() == pass)
                                    {
                                        auth = true;
                                        createFormsAuthTicket(Login1.UserName, Login1.RememberMeSet);
                                    }
                                }
                            }
                        }
                        else
                        {
                            auth = false;
                        }
                    }
                }
            }

            if (auth)
            {
                e.Authenticated = true;
                if (Login1.RememberMeSet == true)
                {
                    remember = true;
                }
                FormsAuthentication.RedirectFromLoginPage(Login1.UserName.ToString(), remember);
                Response.Redirect("Member.aspx");
            }
            else
            {
                e.Authenticated = false;
                Response.Redirect("Default.aspx");
            }
        }