Beispiel #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         Page page = (Page)HttpContext.Current.Handler;
         DataSet1.CustomersDataTable orders;
         DataSet1TableAdapters.CustomersTableAdapter adapter = new DataSet1TableAdapters.CustomersTableAdapter();
         orders = adapter.GetCustomerByEmail(page.User.Identity.Name);
         if (page.User.Identity.IsAuthenticated)
         {
             loggedIn.Value = "true";
         }
         ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "myScriptName", "var Cust_ID = " + Convert.ToInt32(orders[0][0]) + ";", true);
     }
     catch { }
 }
Beispiel #2
0
        // Adds new customer to database if user input is correct (passes the tests function)
        protected void submitBtn_Click(object sender, EventArgs e)
        {
            DataSet1TableAdapters.CustomersTableAdapter adapter = new DataSet1TableAdapters.CustomersTableAdapter();
            if (tests())
            {
                Int32 unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                //emailHandler email_handler = new emailHandler();
                //email_handler.SendVerificationEmail(email.Text, "*****@*****.**");
                byte[] data = System.Text.Encoding.ASCII.GetBytes(password.Text);
                data = new System.Security.Cryptography.SHA256Managed().ComputeHash(data);
                String hash = System.Text.Encoding.ASCII.GetString(data);
                adapter.CreateCustomer(fName.Text, sName.Text, "08/02/1995", email.Text, hash, "123 street"); //, "" + unixTimestamp);
                Page.ClientScript.RegisterStartupScript(GetType(), "MyKey", "successfulRegistration();", true);

                Response.Redirect("/login.aspx");
            }
        }
Beispiel #3
0
        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            try
            {

                DataSet1.CustomersDataTable orders;
                DataSet1TableAdapters.CustomersTableAdapter adapter = new DataSet1TableAdapters.CustomersTableAdapter();
                orders = adapter.GetCustomerByEmail(Login1.UserName);
                e.Authenticated = false;
                //if ((string)orders[0][5] == "yes")
                // {
                //        //Response.Redirect("/accountLocked.aspx?ID=" + Convert.ToInt32(orders[0][0]));
                //    //}
                //    //else if (orders.Count == 1)
                //    //{

                byte[] data = System.Text.Encoding.ASCII.GetBytes(Login1.Password);
                data = new System.Security.Cryptography.SHA256Managed().ComputeHash(data);
                String hash = System.Text.Encoding.ASCII.GetString(data);
                if (hash == (string)orders[0][5])
                {
                    //if ((string)orders[0][7] == "true")
                    //{

                    //adapter.updateLocked("no", 0, Convert.ToInt32(orders[0][0]));
                    e.Authenticated = true;
                    //}
                    //else
                    //{
                    Page.ClientScript.RegisterStartupScript(GetType(), "MyKey", "notActivated();", true);
                    //}
                }
                //}
            }
            catch { }
        }
Beispiel #4
0
        // Server side validation for registeration user input.
        protected bool tests()
        {
            string errorString = "";
            bool validate = true;
            DataSet1.CustomersDataTable orders;
            DataSet1TableAdapters.CustomersTableAdapter adapter = new DataSet1TableAdapters.CustomersTableAdapter();
            try
            {
                orders = adapter.GetCustomerByEmail(email.Text);
                if (orders.Count == 1)
                {
                    validate = false;
                    errorString += "That E-mail address is already in use. Please select another E-mail address. <br />";
                }
            }

            catch { }
            if (email.Text == "")
            {
                validate = false;
                errorString += "You must enter a valid email address. <br />";
            }
            else if (!Regex.IsMatch(email.Text,
                @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
                @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$",
                RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250)))
            {
                validate = false;
                errorString += "You must enter a valid email address. <br />";
            }
            if ((password.Text.Length > 25) || (password.Text.Length < 5))
            {
                validate = false;
                errorString += "Password must contain at least 5 characters and be no longer than 25 characters <br />";
            }
            if (password.Text != passwordConfirm.Text)
            {
                validate = false;
                errorString += "Both passwords must match. <br />";
            }

            //First Name validation
            Match match = Regex.Match(fName.Text, @"^[a-zA-Z]+$");
            if (fName.Text == "")
            {
                errorString += "No first name given <br/>";
                validate = false;
            }
            else if (!match.Success)
            {
                errorString += "First Name must only be characters. <br/>";
                validate = false;
            }
            else if ((fName.Text.Length < 2) || fName.Text.Length > 16)
            {
                errorString += "First Name must be between 1 and 16 characters long. <br />";
                validate = false;
            }

            //Last Name Validation
            match = Regex.Match(sName.Text, @"^[a-zA-Z]+$");
            if (sName.Text == "")
            {
                errorString += "No second name given <br/>";
                validate = false;
            }
            else if (!match.Success)
            {
                errorString += "Second Name must only be characters. <br/>";
                validate = false;
            }
            else if ((sName.Text.Length < 2) || sName.Text.Length > 16)
            {
                errorString += "Second Name must be between 1 and 16 characters long. <br />";
                validate = false;
            }
            failureLbl.Text = errorString;
            return validate;

            return true;
        }