private void ShowPasswordPolicy()
        {
            //SHOW THE PASSWORD POLICY
            CustomerPasswordPolicy policy = new CustomerPasswordPolicy();

            if (policy.MinLength > 0)
            {
                PasswordPolicyLength.Text = string.Format(PasswordPolicyLength.Text, policy.MinLength);
                if (!_PasswordLengthValidatorAdded)
                {
                    RegularExpressionValidator PasswordLengthValidator = new RegularExpressionValidator();
                    PasswordLengthValidator.ID = "PasswordLengthValidator";
                    PasswordLengthValidator.EnableViewState   = false;
                    PasswordLengthValidator.ControlToValidate = "Password";
                    PasswordLengthValidator.Text                 = "*";
                    PasswordLengthValidator.ErrorMessage         = "Password must be at least " + policy.MinLength.ToString() + " characters.";
                    PasswordLengthValidator.ValidationExpression = ".{" + policy.MinLength.ToString() + ",}";
                    PasswordLengthValidator.SetFocusOnError      = false;
                    PasswordLengthValidator.EnableClientScript   = false;
                    PasswordLengthValidator.ValidationGroup      = "Register";
                    PasswordValidatorPanel.Controls.Add(PasswordLengthValidator);
                    _PasswordLengthValidatorAdded = true;
                }
            }
            else
            {
                PasswordPolicyLength.Visible = false;
            }
            List <string> requirements = new List <string>();

            if (policy.RequireUpper)
            {
                requirements.Add("uppercase letter");
            }
            if (policy.RequireLower)
            {
                requirements.Add("lowercase letter");
            }
            if (policy.RequireNumber)
            {
                requirements.Add("number");
            }
            if (policy.RequireSymbol)
            {
                requirements.Add("symbol");
            }
            if (!policy.RequireNumber && !policy.RequireSymbol && policy.RequireNonAlpha)
            {
                requirements.Add("non-letter");
            }
            PasswordPolicyRequired.Visible = (requirements.Count > 0);
            if (PasswordPolicyRequired.Visible)
            {
                if (requirements.Count > 1)
                {
                    requirements[requirements.Count - 1] = "and " + requirements[requirements.Count - 1];
                }
                PasswordPolicyRequired.Text = string.Format(PasswordPolicyRequired.Text, string.Join(", ", requirements.ToArray()));
            }
        }
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                //VERIFY THE NEW PASSWORD MEETS POLICY
                PasswordPolicy policy;
                if (_User.IsAdmin)
                {
                    policy = new MerchantPasswordPolicy();
                }
                else
                {
                    policy = new CustomerPasswordPolicy();
                }

                PasswordTestResult result = policy.TestPasswordWithFeedback(_User, Password.Text);
                if ((result & PasswordTestResult.Success) == PasswordTestResult.Success)
                {
                    _User.SetPassword(Password.Text);
                    _User.Comment = string.Empty;
                    _User.Save();
                    CommerceBuilder.Users.User.Migrate(AbleContext.Current.User, _User);
                    FormsAuthentication.SetAuthCookie(_User.UserName, false);
                    Response.Redirect(AbleCommerce.Code.NavigationHelper.GetHomeUrl());
                }
                else
                {
                    //Your password did not meet the following minimum requirements
                    if ((result & PasswordTestResult.PasswordTooShort) == PasswordTestResult.PasswordTooShort)
                    {
                        AddPasswordValidator("Password length must be at least " + policy.MinLength.ToString() + " characters.");
                    }
                    if ((result & PasswordTestResult.RequireLower) == PasswordTestResult.RequireLower)
                    {
                        AddPasswordValidator("Password must contain at least one lowercase letter.<br/>");
                    }
                    if ((result & PasswordTestResult.RequireUpper) == PasswordTestResult.RequireUpper)
                    {
                        AddPasswordValidator("Password must contain at least one uppercase letter.<br/> ");
                    }
                    if ((result & PasswordTestResult.RequireNonAlpha) == PasswordTestResult.RequireNonAlpha)
                    {
                        AddPasswordValidator("Password must contain at least one non-letter.<br/> ");
                    }
                    if ((result & PasswordTestResult.RequireNumber) == PasswordTestResult.RequireNumber)
                    {
                        AddPasswordValidator("Password must contain at least one number.<br/> ");
                    }
                    if ((result & PasswordTestResult.RequireSymbol) == PasswordTestResult.RequireSymbol)
                    {
                        AddPasswordValidator("Password must contain at least one symbol.<br/> ");
                    }

                    if ((result & PasswordTestResult.PasswordHistoryLimitation) == PasswordTestResult.PasswordHistoryLimitation)
                    {
                        AddPasswordValidator("You have recently used this password.<br/>");
                    }
                }
            }
        }
Пример #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            InstructionText.Text = string.Format(InstructionText.Text, AbleContext.Current.Store.Name);
            if (!Page.IsPostBack)
            {
                HttpCookie usernameCookie = Request.Cookies["UserName"];
                if ((usernameCookie != null) && !string.IsNullOrEmpty(usernameCookie.Value))
                {
                    UserName.Text            = usernameCookie.Value;
                    RememberUserName.Checked = true;
                    Password.Focus();
                }
                else
                {
                    UserName.Focus();
                }
                PasswordExpiredPanel.Visible = false;
                ForgotPasswordPanel.Visible  = false;
                EmailSentPanel.Visible       = false;
                CustomerPasswordPolicy policy = new CustomerPasswordPolicy();
                trCaptchaImage.Visible = policy.ImageCaptcha;
                trCaptchaField.Visible = policy.ImageCaptcha;
            }

            AbleCommerce.Code.PageHelper.ConvertEnterToTab(UserName);
        }
Пример #4
0
        /// <summary>
        /// Validates the password against the effective policy
        /// </summary>
        /// <returns>True if the password is valid, false if it does not meet the policy requirements.</returns>
        private bool ValidatePassword()
        {
            // GET THE INITIAL GROUP SO WE CAN DETERMINE PASSWORD POLICY TO EMPLOY
            int groupId = AlwaysConvert.ToInt(AddGroup.SelectedValue);

            CommerceBuilder.Users.Group group = GroupDataSource.Load(groupId);

            // LOAD THE APPROPRIATE PASSWORD POLICY
            PasswordPolicy policy;

            if (IsAdminGroup(group))
            {
                policy = new MerchantPasswordPolicy();
            }
            else
            {
                policy = new CustomerPasswordPolicy();
            }

            PasswordTestResult result = policy.TestPasswordWithFeedback(null, AddPassword.Text);

            if ((result & PasswordTestResult.Success) != PasswordTestResult.Success)
            {
                // THE PASSWORD DOES NOT MEET THE POLICY
                if ((result & PasswordTestResult.PasswordTooShort) == PasswordTestResult.PasswordTooShort)
                {
                    AddCustomValidationError(phPasswordValidation, AddPassword, "Password length must be at least " + policy.MinLength.ToString() + " characters.");
                }
                if ((result & PasswordTestResult.RequireUpper) == PasswordTestResult.RequireUpper)
                {
                    AddCustomValidationError(phPasswordValidation, AddPassword, "Password must contain at least one uppercase character.");
                }
                if ((result & PasswordTestResult.RequireLower) == PasswordTestResult.RequireLower)
                {
                    AddCustomValidationError(phPasswordValidation, AddPassword, "Password must contain at least one lowercase character.");
                }
                if ((result & PasswordTestResult.RequireNumber) == PasswordTestResult.RequireNumber)
                {
                    AddCustomValidationError(phPasswordValidation, AddPassword, "Password must contain at least one number.");
                }
                if ((result & PasswordTestResult.RequireSymbol) == PasswordTestResult.RequireSymbol)
                {
                    AddCustomValidationError(phPasswordValidation, AddPassword, "Password must contain at least one symbol (e.g. underscore or punctuation)");
                }
                if ((result & PasswordTestResult.RequireSymbol) == PasswordTestResult.RequireSymbol)
                {
                    AddCustomValidationError(phPasswordValidation, AddPassword, "Password must contain at least one symbol (e.g. underscore or punctuation)");
                }
                if ((result & PasswordTestResult.RequireNonAlpha) == PasswordTestResult.RequireNonAlpha)
                {
                    AddCustomValidationError(phPasswordValidation, AddPassword, "Password must contain at least one non-alphabetic character");
                }
                return(false);
            }
            return(true);
        }
        protected bool EnforcePasswordPolicy()
        {
            // DETERMINE THE APPROPRIATE POLICY FOR THE USER
            PasswordPolicy policy;

            if (_User.IsAdmin)
            {
                policy = new MerchantPasswordPolicy();
            }
            else
            {
                policy = new CustomerPasswordPolicy();
            }

            // CHECK IF PASSWORD MEETS POLICY
            PasswordTestResult result = policy.TestPasswordWithFeedback(NewPassword.Text.Trim());

            if ((result & PasswordTestResult.Success) == PasswordTestResult.Success)
            {
                return(true);
            }

            // PASSWORD DOES NOT MEET POLICY
            StringBuilder newErrorMessage = new StringBuilder();

            newErrorMessage.Append(PasswordPolicyValidator.ErrorMessage + "<ul>");
            if ((result & PasswordTestResult.PasswordTooShort) == PasswordTestResult.PasswordTooShort)
            {
                newErrorMessage.Append("<li>New password length must be at least " + policy.MinLength.ToString() + " characters.</li>");
            }
            if ((result & PasswordTestResult.RequireLower) == PasswordTestResult.RequireLower)
            {
                newErrorMessage.Append("<li>New password must contain at least one lowercase letter.<li>");
            }
            if ((result & PasswordTestResult.RequireUpper) == PasswordTestResult.RequireUpper)
            {
                newErrorMessage.Append("<li>New password must contain at least one uppercase letter.</li>");
            }
            if ((result & PasswordTestResult.RequireNonAlpha) == PasswordTestResult.RequireNonAlpha)
            {
                newErrorMessage.Append("<li>New password must contain at least one non-letter.</li>");
            }
            if ((result & PasswordTestResult.RequireNumber) == PasswordTestResult.RequireNumber)
            {
                newErrorMessage.Append("<li>New password must contain at least one number.</li> ");
            }
            if ((result & PasswordTestResult.RequireSymbol) == PasswordTestResult.RequireSymbol)
            {
                newErrorMessage.Append("<li>New password must contain at least one symbol.</li>");
            }
            PasswordPolicyValidator.ErrorMessage = newErrorMessage.ToString() + "</ul>";
            PasswordPolicyValidator.IsValid      = false;
            return(false);
        }
Пример #6
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         MerchantPasswordPolicy merchantPolicy = new MerchantPasswordPolicy();
         MerchantMinLength.Text           = merchantPolicy.MinLength.ToString();
         MerchantRequireUppercase.Checked = merchantPolicy.RequireUpper;
         MerchantRequireLowercase.Checked = merchantPolicy.RequireLower;
         MerchantRequireNumbers.Checked   = merchantPolicy.RequireNumber;
         MerchantRequireSymbols.Checked   = merchantPolicy.RequireSymbol;
         MerchantRequireNonAlpha.Checked  = merchantPolicy.RequireNonAlpha;
         if (merchantPolicy.MaxAge > 0)
         {
             MerchantMaxAge.Text = merchantPolicy.MaxAge.ToString();
         }
         if (merchantPolicy.HistoryDays > 0)
         {
             MerchantPasswordHistoryDays.Text = merchantPolicy.HistoryDays.ToString();
         }
         if (merchantPolicy.HistoryCount > 0)
         {
             MerchantPasswordHistoryCount.Text = merchantPolicy.HistoryCount.ToString();
         }
         MerchantPasswordMaxAttempts.Text    = merchantPolicy.MaxAttempts.ToString();
         MerchantPasswordLockoutPeriod.Text  = merchantPolicy.LockoutPeriod.ToString();
         MerchantPasswordInactivePeriod.Text = merchantPolicy.InactivePeriod.ToString();
         MerchantImageCaptcha.Checked        = merchantPolicy.ImageCaptcha;
         CustomerPasswordPolicy customerPolicy = new CustomerPasswordPolicy();
         CustomerMinLength.Text           = customerPolicy.MinLength.ToString();
         CustomerRequireUppercase.Checked = customerPolicy.RequireUpper;
         CustomerRequireLowercase.Checked = customerPolicy.RequireLower;
         CustomerRequireNumbers.Checked   = customerPolicy.RequireNumber;
         CustomerRequireSymbols.Checked   = customerPolicy.RequireSymbol;
         CustomerRequireNonAlpha.Checked  = customerPolicy.RequireNonAlpha;
         if (customerPolicy.MaxAge > 0)
         {
             CustomerMaxAge.Text = customerPolicy.MaxAge.ToString();
         }
         if (customerPolicy.HistoryDays > 0)
         {
             CustomerPasswordHistoryDays.Text = customerPolicy.HistoryDays.ToString();
         }
         if (customerPolicy.HistoryCount > 0)
         {
             CustomerPasswordHistoryCount.Text = customerPolicy.HistoryCount.ToString();
         }
         CustomerPasswordMaxAttempts.Text   = customerPolicy.MaxAttempts.ToString();
         CustomerPasswordLockoutPeriod.Text = customerPolicy.LockoutPeriod.ToString();
         CustomerImageCaptcha.Checked       = customerPolicy.ImageCaptcha;
     }
 }
Пример #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                HttpCookie usernameCookie = Request.Cookies["UserName"];
                if ((usernameCookie != null) && !string.IsNullOrEmpty(usernameCookie.Value))
                {
                    UserName.Text            = usernameCookie.Value;
                    RememberUserName.Checked = true;
                    Password.Focus();
                }
                else
                {
                    UserName.Focus();
                }
                PasswordExpiredPanel.Visible = false;
                ForgotPasswordPanel.Visible  = false;
                EmailSentPanel.Visible       = false;
                CustomerPasswordPolicy policy = new CustomerPasswordPolicy();
                trCaptchaField.Visible = policy.ImageCaptcha;
                trCaptchaImage.Visible = policy.ImageCaptcha;
            }

            AbleCommerce.Code.PageHelper.ConvertEnterToTab(UserName);
            // SET DEFALUT BUTTONS FOR INPUT FIELDS
            if (trCaptchaImage.Visible)
            {
                AbleCommerce.Code.PageHelper.ConvertEnterToTab(Password);
                WebControl inputControl = CaptchaImage.FindControl("CaptchaInput") as WebControl;
                if (inputControl != null)
                {
                    AbleCommerce.Code.PageHelper.SetDefaultButton(inputControl, LoginButton.ClientID);
                }
            }
            else
            {
                AbleCommerce.Code.PageHelper.SetDefaultButton(Password, LoginButton.ClientID);
            }

            bool hasDigitalGoods  = _Basket.Items.HasDigitalGoods();
            bool hasSubscriptions = _Basket.Items.HasSubscriptions();

            if (hasDigitalGoods || hasSubscriptions)
            {
                GuestCheckoutPanel.Visible = _settings.AllowAnonymousCheckout && _settings.AllowAnonymousCheckoutForDigitalGoods;
            }
            else
            {
                GuestCheckoutPanel.Visible = _settings.AllowAnonymousCheckout;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            AbleCommerce.Code.PageHelper.ConvertEnterToTab(UserName);
            AbleCommerce.Code.PageHelper.ConvertEnterToTab(Password);
            AbleCommerce.Code.PageHelper.SetDefaultButton(ConfirmPassword, RegisterButton.ClientID);
            ShowPasswordPolicy();

            if (!Page.IsPostBack)
            {
                CustomerPasswordPolicy policy = new CustomerPasswordPolicy();
                trCaptchaImage.Visible = policy.ImageCaptcha;
                trCaptchaField.Visible = policy.ImageCaptcha;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                InitAddressForm();

                CustomerPasswordPolicy policy = new CustomerPasswordPolicy();
                trCaptchaImage.Visible = policy.ImageCaptcha;
                trCaptchaField.Visible = policy.ImageCaptcha;
            }

            IntializeCreateAccountPanel();
            IntializeShippingPanel();
            IntializeEmailLists();
            PasswordValidatorPanel.Controls.Clear();
        }
Пример #10
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            int merchantMinLength = AlwaysConvert.ToInt(MerchantMinLength.Text);
            int customerMinLength = AlwaysConvert.ToInt(CustomerMinLength.Text);

            if (merchantMinLength < 1)
            {
                MerchantMinLengthValidator1.IsValid = false;
            }
            if (customerMinLength < 1)
            {
                CustomerMinLengthValidator1.IsValid = false;
            }
            if (Page.IsValid)
            {
                MerchantPasswordPolicy merchantPolicy = new MerchantPasswordPolicy();
                merchantPolicy.MinLength       = merchantMinLength;
                merchantPolicy.RequireUpper    = MerchantRequireUppercase.Checked;
                merchantPolicy.RequireLower    = MerchantRequireLowercase.Checked;
                merchantPolicy.RequireNumber   = MerchantRequireNumbers.Checked;
                merchantPolicy.RequireSymbol   = MerchantRequireSymbols.Checked;
                merchantPolicy.RequireNonAlpha = MerchantRequireNonAlpha.Checked;
                merchantPolicy.MaxAge          = AlwaysConvert.ToInt(MerchantMaxAge.Text);
                merchantPolicy.HistoryDays     = AlwaysConvert.ToInt(MerchantPasswordHistoryDays.Text);
                merchantPolicy.HistoryCount    = AlwaysConvert.ToInt(MerchantPasswordHistoryCount.Text);
                merchantPolicy.MaxAttempts     = AlwaysConvert.ToInt(MerchantPasswordMaxAttempts.Text);
                merchantPolicy.LockoutPeriod   = AlwaysConvert.ToInt(MerchantPasswordLockoutPeriod.Text);
                merchantPolicy.InactivePeriod  = AlwaysConvert.ToInt(MerchantPasswordInactivePeriod.Text);
                merchantPolicy.ImageCaptcha    = MerchantImageCaptcha.Checked;
                merchantPolicy.Save();
                CustomerPasswordPolicy customerPolicy = new CustomerPasswordPolicy();
                customerPolicy.MinLength       = customerMinLength;
                customerPolicy.RequireUpper    = CustomerRequireUppercase.Checked;
                customerPolicy.RequireLower    = CustomerRequireLowercase.Checked;
                customerPolicy.RequireNumber   = CustomerRequireNumbers.Checked;
                customerPolicy.RequireSymbol   = CustomerRequireSymbols.Checked;
                customerPolicy.RequireNonAlpha = CustomerRequireNonAlpha.Checked;
                customerPolicy.MaxAge          = AlwaysConvert.ToInt(CustomerMaxAge.Text);
                customerPolicy.HistoryDays     = AlwaysConvert.ToInt(CustomerPasswordHistoryDays.Text);
                customerPolicy.HistoryCount    = AlwaysConvert.ToInt(CustomerPasswordHistoryCount.Text);
                customerPolicy.MaxAttempts     = AlwaysConvert.ToInt(CustomerPasswordMaxAttempts.Text);
                customerPolicy.LockoutPeriod   = AlwaysConvert.ToInt(CustomerPasswordLockoutPeriod.Text);
                customerPolicy.ImageCaptcha    = CustomerImageCaptcha.Checked;
                customerPolicy.Save();
                SavedMessage.Visible = true;
            }
        }
Пример #11
0
        private bool ValidatePassword()
        {
            //VALIDATE PASSWORD POLICY
            CustomerPasswordPolicy policy = new CustomerPasswordPolicy();

            if (!policy.TestPassword(null, Password.Text))
            {
                CustomValidator policyValidator = new CustomValidator();
                policyValidator.ControlToValidate = "Password";
                policyValidator.IsValid           = false;
                policyValidator.Text            = "*";
                policyValidator.ErrorMessage    = "The password does not meet the minimum requirements.";
                policyValidator.SetFocusOnError = false;
                PasswordValidatorPanel.Controls.Add(policyValidator);
                return(false);
            }
            return(true);
        }
Пример #12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                HttpCookie usernameCookie = Request.Cookies["UserName"];
                if ((usernameCookie != null) && !string.IsNullOrEmpty(usernameCookie.Value))
                {
                    UserName.Text            = usernameCookie.Value;
                    RememberUserName.Checked = true;
                    Password.Focus();
                }
                else
                {
                    UserName.Focus();
                }
                PasswordExpiredPanel.Visible = false;
                //ForgotPasswordPanel.Visible = false;
                //EmailSentPanel.Visible = false;

                CustomerPasswordPolicy policy = new CustomerPasswordPolicy();
                trCaptchaImage.Visible = policy.ImageCaptcha;
                trCaptchaField.Visible = policy.ImageCaptcha;
            }

            AbleCommerce.Code.PageHelper.ConvertEnterToTab(UserName);
            // SET DEFALUT BUTTONS FOR INPUT FIELDS

            AbleCommerce.Code.PageHelper.SetDefaultButton(Password, LoginButton.ClientID);

            bool hasDigitalGoods = _Basket.Items.HasDigitalGoods();

            if (hasDigitalGoods)
            {
                GuestCheckoutPanel.Visible = _settings.AllowAnonymousCheckout && _settings.AllowAnonymousCheckoutForDigitalGoods;
            }
            else
            {
                GuestCheckoutPanel.Visible = _settings.AllowAnonymousCheckout;
            }

            CreateAccountAndCheckoutButton.NavigateUrl = NavigationHelper.GetMobileStoreUrl("~/Checkout/EditBillAddress.aspx");
            GuestCheckoutButton.NavigateUrl            = NavigationHelper.GetMobileStoreUrl("~/Checkout/EditBillAddress.aspx?GC=0");
        }
Пример #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            InstructionText.Text = string.Format(InstructionText.Text, AbleContext.Current.Store.Name);
            if (!Page.IsPostBack)
            {
                HttpCookie usernameCookie = Request.Cookies["UserName"];
                if ((usernameCookie != null) && !string.IsNullOrEmpty(usernameCookie.Value))
                {
                    UserName.Text            = usernameCookie.Value;
                    RememberUserName.Checked = true;
                    Password.Focus();
                }
                else
                {
                    UserName.Focus();
                }
                PasswordExpiredPanel.Visible = false;
                ForgotPasswordPanel.Visible  = false;
                EmailSentPanel.Visible       = false;
                CustomerPasswordPolicy policy = new CustomerPasswordPolicy();
                trCaptchaField.Visible = policy.ImageCaptcha;
                trCaptchaImage.Visible = policy.ImageCaptcha;
            }

            AbleCommerce.Code.PageHelper.ConvertEnterToTab(UserName);
            // SET DEFALUT BUTTONS FOR INPUT FIELDS
            if (trCaptchaImage.Visible)
            {
                AbleCommerce.Code.PageHelper.ConvertEnterToTab(Password);
                WebControl inputControl = CaptchaImage.FindControl("CaptchaInput") as WebControl;
                if (inputControl != null)
                {
                    AbleCommerce.Code.PageHelper.SetDefaultButton(inputControl, LoginButton.ClientID);
                }
            }
            else
            {
                AbleCommerce.Code.PageHelper.SetDefaultButton(Password, LoginButton.ClientID);
            }
        }
        private bool ValidatePassword()
        {
            //VALIDATE PASSWORD POLICY
            CustomerPasswordPolicy policy = new CustomerPasswordPolicy();

            if (!policy.TestPassword(null, Password.Text))
            {
                CustomValidator policyValidator = new CustomValidator();
                policyValidator.ControlToValidate = "Password";
                policyValidator.IsValid           = false;
                policyValidator.Text            = "*";
                policyValidator.ErrorMessage    = "The password does not meet the minimum requirements.";
                policyValidator.SetFocusOnError = false;
                policyValidator.ValidationGroup = ValidationGroupName;
                policyValidator.CssClass        = "requiredField";
                PasswordValidatorPanel.Controls.Add(policyValidator);

                // CELAR PASSWORD
                Password.Attributes.Add("value", string.Empty);
                ConfirmPassword.Attributes.Add("value", string.Empty);
                return(false);
            }
            return(true);
        }
Пример #15
0
        protected void LoginButton_Click(object sender, EventArgs e)
        {
            _LastPasswordValue = Password.Text;
            User loginUser = UserDataSource.LoadForUserName(UserName.Text);

            if (loginUser != null)
            {
                bool stillNeedsCaptcha = false;
                if ((loginUser.IsAdmin) && (!trCaptchaField.Visible))
                {
                    stillNeedsCaptcha = (new MerchantPasswordPolicy()).ImageCaptcha;
                }
                if (!stillNeedsCaptcha)
                {
                    //EITHER THIS IS NOT AN ADMIN USER, OR THE CAPTCHA IS ALREADY VISIBLE
                    if ((!trCaptchaField.Visible) || (CaptchaImage.Authenticate(CaptchaInput.Text)))
                    {
                        //CAPTCHA IS HIDDEN OR VALIDATED, PROCEED WITH LOGIN ATTEMPT
                        if (Membership.ValidateUser(UserName.Text, Password.Text))
                        {
                            //LOGIN SUCCEEDED, MIGRATE USER IF NEEDED
                            int newUserId = loginUser.Id;
                            int oldUserId = AbleContext.Current.UserId;
                            if ((oldUserId != newUserId) && (newUserId != 0))
                            {
                                User.Migrate(AbleContext.Current.User, UserDataSource.Load(newUserId));
                                AbleContext.Current.UserId = newUserId;
                            }
                            //HANDLE LOGIN PROCESSING
                            if (trRememberMe.Visible && RememberUserName.Checked)
                            {
                                HttpCookie cookie = new HttpCookie("UserName", UserName.Text);
                                cookie.Expires = DateTime.MaxValue;
                                Response.Cookies.Add(cookie);
                            }
                            else
                            {
                                Response.Cookies.Add(new HttpCookie("UserName", ""));
                            }
                            //CHECK FOR EXPIRED PASSWORDS
                            PasswordPolicy policy;
                            if (loginUser.IsAdmin)
                            {
                                policy = new MerchantPasswordPolicy();
                            }
                            else
                            {
                                policy = new CustomerPasswordPolicy();
                            }
                            if (policy.IsPasswordExpired(loginUser))
                            {
                                ShowPasswordExpired(policy, loginUser);
                            }
                            else
                            {
                                switch (AbleContext.Current.Store.Settings.RestrictStoreAccess)
                                {
                                case AccessRestrictionType.AuthorizedGroupsOnly:
                                    if (!loginUser.IsAdmin && !loginUser.IsAuthorizedUser)
                                    {
                                        // STORE ACCESS IS RESTRICTED TO AUTHORIZED USERS ONLY
                                        LoginPanel.Visible                  = false;
                                        PasswordExpiredPanel.Visible        = false;
                                        StoreFrontAccessDeniedPanel.Visible = true;
                                    }
                                    else
                                    {
                                        FormsAuthentication.RedirectFromLoginPage(UserName.Text, false);
                                    }
                                    break;

                                case AccessRestrictionType.RegisteredUsersOnly:
                                case AccessRestrictionType.None:
                                    //REDIRECT TO THE STANDARD PAGE
                                    FormsAuthentication.RedirectFromLoginPage(UserName.Text, false);
                                    break;
                                }
                            }
                        }
                        else
                        {
                            if (loginUser != null)
                            {
                                if (!loginUser.IsApproved)
                                {
                                    AccountDisabled.IsValid = false;
                                }
                                else
                                {
                                    PasswordPolicy policy;
                                    if (loginUser.IsAdmin)
                                    {
                                        policy = new MerchantPasswordPolicy();
                                    }
                                    else
                                    {
                                        policy = new CustomerPasswordPolicy();
                                    }
                                    int remainingTries = policy.MaxAttempts - loginUser.FailedPasswordAttemptCount;
                                    if (!loginUser.IsLockedOut && remainingTries > 0)
                                    {
                                        InvalidLogin.ErrorMessage += " You have {0} tries remaining.";
                                        InvalidLogin.ErrorMessage  = String.Format(InvalidLogin.ErrorMessage, remainingTries);
                                        InvalidLogin.IsValid       = false;
                                    }
                                    else
                                    {
                                        AccountLocked.ErrorMessage = String.Format(AccountLocked.ErrorMessage, policy.LockoutPeriod);
                                        AccountLocked.IsValid      = false;
                                    }
                                }
                            }
                            else
                            {
                                InvalidLogin.IsValid = false;
                            }
                        }
                    }
                    else
                    {
                        //CAPTCHA IS VISIBLE AND DID NOT AUTHENTICATE
                        CustomValidator invalidInput = new CustomValidator();
                        invalidInput.ValidationGroup = "Login";
                        invalidInput.Text            = "*";
                        invalidInput.ErrorMessage    = "You did not input the verification number correctly.";
                        invalidInput.IsValid         = false;
                        phCaptchaValidators.Controls.Add(invalidInput);
                        CaptchaInput.Text = "";
                        Password.Attributes.Add("value", string.Empty);
                        RefreshCaptcha();
                    }
                }
                else
                {
                    //THIS IS AN ADMIN USER AND CAPTCHA IS NOT DISPLAYED YET
                    trCaptchaField.Visible     = true;
                    trCaptchaImage.Visible     = true;
                    trRememberMe.Visible       = _EnableAdminRememberMe;
                    CaptchaImage.ChallengeText = StringHelper.RandomNumber(6);
                    CustomValidator needsCaptcha = new CustomValidator();
                    needsCaptcha.ValidationGroup = "Login";
                    needsCaptcha.Text            = "*";
                    needsCaptcha.ErrorMessage    = "Please type the verification number to log in.";
                    needsCaptcha.IsValid         = false;
                    phCaptchaValidators.Controls.Add(needsCaptcha);
                    Password.Attributes.Add("value", Password.Text);
                }
            }
            else
            {
                //THIS IS AN INVALID USER NAME
                InvalidLogin.IsValid = false;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _UserId = AlwaysConvert.ToInt(Request.QueryString["UserId"]);
            _User   = UserDataSource.Load(_UserId);

            if (!Page.IsPostBack)
            {
                // INITIALIZE LEFT COLUMN WITH ADJUSTABLE ACCOUNT SETTINGS
                UserName.Text      = _User.UserName;
                Email.Text         = _User.Email;
                IsDisabled.Enabled = (_User.Id != AbleContext.Current.UserId);
                IsDisabled.Checked = !_User.IsApproved;
                ListItem selectedItem = TaxExemptionType.Items.FindByValue(((int)_User.TaxExemptionType).ToString());
                if (selectedItem != null)
                {
                    TaxExemptionType.SelectedIndex = TaxExemptionType.Items.IndexOf(selectedItem);
                }
                TaxExemptionReference.Text = _User.TaxExemptionReference;
            }

            InitializeChangeGroupsJS();

            // INITIALIZE RIGHT COLUMN OF PASSWORD DETAILS
            RegisteredSinceDate.Text = _User.CreateDate.ToString("g");
            if (_User.LastActivityDate.HasValue && _User.LastActivityDate > System.DateTime.MinValue)
            {
                LastActiveDate.Text = _User.LastActivityDate.Value.ToString("g");
            }
            FailedLoginCount.Text = _User.FailedPasswordAttemptCount.ToString();
            if (_User.LastLockoutDate.HasValue && _User.LastLockoutDate > System.DateTime.MinValue)
            {
                LastLockoutDate.Text = _User.LastLockoutDate.Value.ToString("g");
            }
            if (_User.Passwords.Count > 0)
            {
                TimeSpan ts = LocaleHelper.LocalNow - _User.Passwords[0].CreateDate;
                string   timeSpanPhrase;
                if (ts.Days > 0)
                {
                    timeSpanPhrase = ts.Days.ToString() + " days";
                }
                else if (ts.Hours > 0)
                {
                    timeSpanPhrase = ts.Hours.ToString() + " hours";
                }
                else
                {
                    timeSpanPhrase = ts.Minutes.ToString() + " minutes";
                }
                PasswordLastChangedText.Text = string.Format(PasswordLastChangedText.Text, timeSpanPhrase);
            }
            else
            {
                PasswordLastChangedText.Visible = false;
            }

            // DISPLAY POLICY ON CHANGE PASSWORD FORM
            PasswordPolicy policy;

            if (_User.IsAdmin)
            {
                policy = new MerchantPasswordPolicy();
            }
            else
            {
                policy = new CustomerPasswordPolicy();
            }
            PasswordPolicyLength.Text = string.Format(PasswordPolicyLength.Text, policy.MinLength);
            List <string> requirements = new List <string>();

            if (policy.RequireUpper)
            {
                requirements.Add("uppercase letter");
            }
            if (policy.RequireLower)
            {
                requirements.Add("lowercase letter");
            }
            if (policy.RequireNumber)
            {
                requirements.Add("number");
            }
            if (policy.RequireSymbol)
            {
                requirements.Add("symbol");
            }
            if (!policy.RequireNumber && !policy.RequireSymbol && policy.RequireNonAlpha)
            {
                requirements.Add("non-letter");
            }
            PasswordPolicyRequired.Visible = (requirements.Count > 0);
            if (PasswordPolicyRequired.Visible)
            {
                if (requirements.Count > 1)
                {
                    requirements[requirements.Count - 1] = "and " + requirements[requirements.Count - 1];
                }
                PasswordPolicyRequired.Text = string.Format(PasswordPolicyRequired.Text, string.Join(", ", requirements.ToArray()));
            }

            bool showLoginAs = ((_User.Id != AbleContext.Current.UserId) && (!_User.IsAdmin));

            if (showLoginAs)
            {
                LoginUserButton.Visible       = true;
                LoginUserButton.OnClientClick = string.Format(LoginUserButton.OnClientClick, _User.UserName);
            }
            else
            {
                LoginUserButton.Visible = false;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            User user = AbleContext.Current.User;

            if (!user.IsAnonymousOrGuest)
            {
                // handling for registered users
                NewAccountText.Visible    = false;
                UpdateAccountText.Visible = true;
                if (!Page.IsPostBack)
                {
                    UserName.Text = user.UserName;
                    Email.Text    = user.Email;
                }
            }
            else
            {
                // handling for guest users
                if (!Page.IsPostBack)
                {
                    // TRY TO DEFAULT THE EMAIL ADDRESS TO LAST ORDER EMAIL
                    int orderCount = user.Orders.Count;
                    if (orderCount > 0)
                    {
                        UserName.Text = user.Orders[orderCount - 1].BillToEmail;
                        Email.Text    = UserName.Text;
                    }
                }

                // CONFIGURE SCREEN FOR NEW ACCOUNT CREATION
                trCurrentPassword.Visible = false;
                NewAccountText.Visible    = true;
                UpdateAccountText.Visible = false;
            }

            PasswordPolicy policy;

            if (user.IsAdmin)
            {
                policy = new MerchantPasswordPolicy();
            }
            else
            {
                policy = new CustomerPasswordPolicy();
            }
            PasswordPolicyLength.Text          = string.Format(PasswordPolicyLength.Text, policy.MinLength);
            PasswordPolicyHistoryCount.Visible = (policy.HistoryCount > 0);
            if (PasswordPolicyHistoryCount.Visible)
            {
                PasswordPolicyHistoryCount.Text = string.Format(PasswordPolicyHistoryCount.Text, policy.HistoryCount);
            }
            PasswordPolicyHistoryDays.Visible = (policy.HistoryDays > 0);
            if (PasswordPolicyHistoryDays.Visible)
            {
                PasswordPolicyHistoryDays.Text = string.Format(PasswordPolicyHistoryDays.Text, policy.HistoryDays);
            }
            List <string> requirements = new List <string>();

            if (policy.RequireUpper)
            {
                requirements.Add("uppercase letter");
            }
            if (policy.RequireLower)
            {
                requirements.Add("lowercase letter");
            }
            if (policy.RequireNumber)
            {
                requirements.Add("number");
            }
            if (policy.RequireSymbol)
            {
                requirements.Add("symbol");
            }
            if (!policy.RequireNumber && !policy.RequireSymbol && policy.RequireNonAlpha)
            {
                requirements.Add("non-letter");
            }
            PasswordPolicyRequired.Visible = (requirements.Count > 0);
            if (PasswordPolicyRequired.Visible)
            {
                if (requirements.Count > 1)
                {
                    requirements[requirements.Count - 1] = "and " + requirements[requirements.Count - 1];
                }
                PasswordPolicyRequired.Text = string.Format(PasswordPolicyRequired.Text, string.Join(", ", requirements.ToArray()));
            }

            phReviewReminders.Visible = _settings.ProductReviewEnabled != UserAuthFilter.None && _settings.ProductReviewReminderEnabled;
            if (!Page.IsPostBack)
            {
                ReviewReminders.Checked = !user.Settings.OptOutReviewReminders;
            }

            trEmailPrefs.Visible = phReviewReminders.Visible || phEmailLists.Visible;
        }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                User   user            = AbleContext.Current.User;
                string currentUserName = user.UserName;

                // VALIDATE THE PASSWORD IF THIS IS NOT AN ANONYMOUS USER
                bool validPassword;
                if (!user.IsAnonymousOrGuest)
                {
                    validPassword = Membership.ValidateUser(currentUserName, CurrentPassword.Text);
                    if (!validPassword)
                    {
                        InvalidPassword.IsValid = false;
                        return;
                    }
                }
                else
                {
                    validPassword = true;
                }

                // VALIDATE NEW PASSWORD AGASINT POLICY
                if (Password.Text.Length > 0)
                {
                    PasswordPolicy policy;
                    if (user.IsAdmin)
                    {
                        policy = new MerchantPasswordPolicy();
                    }
                    else
                    {
                        policy = new CustomerPasswordPolicy();
                    }
                    PasswordTestResult result = policy.TestPasswordWithFeedback(user, Password.Text);
                    if ((result & PasswordTestResult.Success) != PasswordTestResult.Success)
                    {
                        PasswordPolicyValidator.ErrorMessage += "<UL>";
                        if ((result & PasswordTestResult.PasswordTooShort) == PasswordTestResult.PasswordTooShort)
                        {
                            AddPwdValidationError(string.Format(PasswordPolicyLength.Text, policy.MinLength));
                        }
                        if ((result & PasswordTestResult.RequireLower) == PasswordTestResult.RequireLower)
                        {
                            AddPwdValidationError("New password must contain at least one lowercase letter.");
                        }
                        if ((result & PasswordTestResult.RequireUpper) == PasswordTestResult.RequireUpper)
                        {
                            AddPwdValidationError("New password must contain at least one uppercase letter. ");
                        }
                        if ((result & PasswordTestResult.RequireNonAlpha) == PasswordTestResult.RequireNonAlpha)
                        {
                            AddPwdValidationError("New password must contain at least one non-letter.");
                        }
                        if ((result & PasswordTestResult.RequireNumber) == PasswordTestResult.RequireNumber)
                        {
                            AddPwdValidationError("New password must contain at least one number.");
                        }
                        if ((result & PasswordTestResult.RequireSymbol) == PasswordTestResult.RequireSymbol)
                        {
                            AddPwdValidationError("New password must contain at least one symbol.");
                        }
                        if ((result & PasswordTestResult.PasswordHistoryLimitation) == PasswordTestResult.PasswordHistoryLimitation)
                        {
                            AddPwdValidationError("You have recently used this password.");
                        }
                        PasswordPolicyValidator.ErrorMessage += "</UL>";
                        PasswordPolicyValidator.IsValid       = false;
                        return;
                    }
                }
                else if (user.IsAnonymousOrGuest)
                {
                    // PASSWORD IS REQUIRED FOR NEW ANONYMOUS ACCOUNTS
                    PasswordRequiredValidator.IsValid = false;
                    return;
                }

                // IF USERNAME IS CHANGED, VALIDATE THE NEW NAME IS AVAILABLE
                string newUserName     = UserName.Text.Trim();
                bool   userNameChanged = (currentUserName != newUserName);
                if (userNameChanged)
                {
                    // CHECK IF THERE IS ALREADY A USER WITH DESIRED USERNAME
                    if (UserDataSource.GetUserIdByUserName(newUserName) > 0)
                    {
                        // A USER ALREADY EXISTS WITH THAT NAME
                        phUserNameUnavailable.Visible = true;
                        return;
                    }
                }

                // OPT-OUT REVIEW REMINDERS
                user.Settings.OptOutReviewReminders = !ReviewReminders.Checked;

                // UPDATE THE USER RECORD WITH NEW VALUES
                user.Email = Email.Text.Trim();
                user.PrimaryAddress.Email = user.Email;
                user.UserName             = newUserName;
                user.Save();

                // RESET AUTH COOKIE WITH NEW USERNAME IF NEEDED
                if (userNameChanged)
                {
                    FormsAuthentication.SetAuthCookie(newUserName, false);
                }

                // UPDATE PASSWORD IF INDICATED
                if (Password.Text.Length > 0)
                {
                    user.SetPassword(Password.Text);
                }

                // UPDATE MAILING PREFERENCES
                if (phEmailLists.Visible)
                {
                    UpdateEmailLists();
                }

                // DISPLAY RESULT
                SavedMessage.Visible = true;
            }
        }
Пример #19
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                User   user            = AbleContext.Current.User;
                string currentUserName = user.UserName;

                // VALIDATE THE PASSWORD IF THIS IS NOT AN ANONYMOUS USER
                bool validPassword;
                if (!user.IsAnonymousOrGuest)
                {
                    validPassword = Membership.ValidateUser(currentUserName, CurrentPassword.Text);
                    if (!validPassword)
                    {
                        InvalidPassword.IsValid = false;
                        return;
                    }
                }
                else
                {
                    validPassword = true;
                }

                // VALIDATE NEW PASSWORD AGASINT POLICY
                if (Password.Text.Length > 0)
                {
                    PasswordPolicy policy;
                    if (user.IsAdmin)
                    {
                        policy = new MerchantPasswordPolicy();
                    }
                    else
                    {
                        policy = new CustomerPasswordPolicy();
                    }
                    PasswordTestResult result = policy.TestPasswordWithFeedback(user, Password.Text);
                    if ((result & PasswordTestResult.Success) != PasswordTestResult.Success)
                    {
                        PasswordPolicyValidator.ErrorMessage += "<UL>";
                        if ((result & PasswordTestResult.PasswordTooShort) == PasswordTestResult.PasswordTooShort)
                        {
                            AddPwdValidationError(string.Format(PasswordPolicyLength.Text, policy.MinLength));
                        }
                        if ((result & PasswordTestResult.RequireLower) == PasswordTestResult.RequireLower)
                        {
                            AddPwdValidationError("New password must contain at least one lowercase letter.");
                        }
                        if ((result & PasswordTestResult.RequireUpper) == PasswordTestResult.RequireUpper)
                        {
                            AddPwdValidationError("New password must contain at least one uppercase letter. ");
                        }
                        if ((result & PasswordTestResult.RequireNonAlpha) == PasswordTestResult.RequireNonAlpha)
                        {
                            AddPwdValidationError("New password must contain at least one non-letter.");
                        }
                        if ((result & PasswordTestResult.RequireNumber) == PasswordTestResult.RequireNumber)
                        {
                            AddPwdValidationError("New password must contain at least one number.");
                        }
                        if ((result & PasswordTestResult.RequireSymbol) == PasswordTestResult.RequireSymbol)
                        {
                            AddPwdValidationError("New password must contain at least one symbol.");
                        }
                        if ((result & PasswordTestResult.PasswordHistoryLimitation) == PasswordTestResult.PasswordHistoryLimitation)
                        {
                            AddPwdValidationError("You have recently used this password.");
                        }
                        PasswordPolicyValidator.ErrorMessage += "</UL>";
                        PasswordPolicyValidator.IsValid       = false;
                        return;
                    }
                }
                else if (user.IsAnonymousOrGuest)
                {
                    // PASSWORD IS REQUIRED FOR NEW ANONYMOUS ACCOUNTS
                    PasswordRequiredValidator.IsValid = false;
                    return;
                }

                // UPDATE THE USER RECORD WITH NEW VALUES
                user.Save();

                // UPDATE PASSWORD IF INDICATED
                if (Password.Text.Length > 0)
                {
                    user.SetPassword(Password.Text);
                }

                // DISPLAY RESULT
                ConfirmationMsg.Visible = true;
            }
        }
Пример #20
0
        protected void Page_Load(object sender, EventArgs e)
        {
            User user = AbleContext.Current.User;

            // CONFIGURE SCREEN FOR NEW ACCOUNT CREATION
            trCurrentPassword.Visible = true;
            NewAccountText.Visible    = false;
            UpdateAccountText.Visible = true;

            PasswordPolicy policy;

            if (user.IsAdmin)
            {
                policy = new MerchantPasswordPolicy();
            }
            else
            {
                policy = new CustomerPasswordPolicy();
            }
            PasswordPolicyLength.Text          = string.Format(PasswordPolicyLength.Text, policy.MinLength);
            PasswordPolicyHistoryCount.Visible = (policy.HistoryCount > 0);
            if (PasswordPolicyHistoryCount.Visible)
            {
                PasswordPolicyHistoryCount.Text = string.Format(PasswordPolicyHistoryCount.Text, policy.HistoryCount);
            }
            PasswordPolicyHistoryDays.Visible = (policy.HistoryDays > 0);
            if (PasswordPolicyHistoryDays.Visible)
            {
                PasswordPolicyHistoryDays.Text = string.Format(PasswordPolicyHistoryDays.Text, policy.HistoryDays);
            }
            List <string> requirements = new List <string>();

            if (policy.RequireUpper)
            {
                requirements.Add("uppercase letter");
            }
            if (policy.RequireLower)
            {
                requirements.Add("lowercase letter");
            }
            if (policy.RequireNumber)
            {
                requirements.Add("number");
            }
            if (policy.RequireSymbol)
            {
                requirements.Add("symbol");
            }
            if (!policy.RequireNumber && !policy.RequireSymbol && policy.RequireNonAlpha)
            {
                requirements.Add("non-letter");
            }
            PasswordPolicyRequired.Visible = (requirements.Count > 0);
            if (PasswordPolicyRequired.Visible)
            {
                if (requirements.Count > 1)
                {
                    requirements[requirements.Count - 1] = "and " + requirements[requirements.Count - 1];
                }
                PasswordPolicyRequired.Text = string.Format(PasswordPolicyRequired.Text, string.Join(", ", requirements.ToArray()));
            }
        }
Пример #21
0
        protected void Page_Init(object sender, EventArgs e)
        {
            _UserId = AlwaysConvert.ToInt(Request.QueryString["Key"]);
            _User   = UserDataSource.Load(_UserId);
            if ((_User == null) || (!_User.IsApproved))
            {
                Response.Redirect(AbleCommerce.Code.NavigationHelper.GetHomeUrl());
            }
            string tempPassword = AlwaysConvert.ToString(Request.QueryString["Check"]);

            if (string.IsNullOrEmpty(tempPassword) || (_User.Comment != tempPassword))
            {
                Response.Redirect(AbleCommerce.Code.NavigationHelper.GetHomeUrl());
            }
            if (!Page.IsPostBack)
            {
                // CHECK IF THERE IS ALREADY A USER WITH DESIRED USERNAME
                if (_User.IsAnonymousOrGuest && UserDataSource.GetUserIdByUserName(_User.Email) == 0)
                {
                    UserName.Text = _User.Email;
                }
                else
                {
                    UserName.Text = _User.UserName;
                }
                // PASSWORD POLICY
                PasswordPolicy policy;
                if (_User.IsAdmin)
                {
                    policy = new MerchantPasswordPolicy();
                }
                else
                {
                    policy = new CustomerPasswordPolicy();
                }
                PasswordPolicyLength.Text          = string.Format(PasswordPolicyLength.Text, policy.MinLength);
                PasswordPolicyHistoryCount.Visible = (policy.HistoryCount > 0);
                if (PasswordPolicyHistoryCount.Visible)
                {
                    PasswordPolicyHistoryCount.Text = string.Format(PasswordPolicyHistoryCount.Text, policy.HistoryCount);
                }
                PasswordPolicyHistoryDays.Visible = (policy.HistoryDays > 0);
                if (PasswordPolicyHistoryDays.Visible)
                {
                    PasswordPolicyHistoryDays.Text = string.Format(PasswordPolicyHistoryDays.Text, policy.HistoryDays);
                }
                List <string> requirements = new List <string>();
                if (policy.RequireUpper)
                {
                    requirements.Add("uppercase letter");
                }
                if (policy.RequireLower)
                {
                    requirements.Add("lowercase letter");
                }
                if (policy.RequireNumber)
                {
                    requirements.Add("number");
                }
                if (policy.RequireSymbol)
                {
                    requirements.Add("symbol");
                }
                if (!policy.RequireNumber && !policy.RequireSymbol && policy.RequireNonAlpha)
                {
                    requirements.Add("non-letter");
                }
                PasswordPolicyRequired.Visible = (requirements.Count > 0);
                if (PasswordPolicyRequired.Visible)
                {
                    if (requirements.Count > 1)
                    {
                        requirements[requirements.Count - 1] = "and " + requirements[requirements.Count - 1];
                    }
                    PasswordPolicyRequired.Text = string.Format(PasswordPolicyRequired.Text, string.Join(", ", requirements.ToArray()));
                }
            }
        }
Пример #22
0
        protected void LoginButton_Click(object sender, EventArgs e)
        {
            _LastPasswordValue = Password.Text;
            User loginUser = UserDataSource.LoadForUserName(UserName.Text);

            if (loginUser != null)
            {
                bool stillNeedsCaptcha = false;
                if ((loginUser.IsAdmin) && (!trCaptchaField.Visible))
                {
                    stillNeedsCaptcha = (new MerchantPasswordPolicy()).ImageCaptcha;
                }

                if (!stillNeedsCaptcha)
                {
                    // IF CAPTCHA IS REQUIRED CHECK IF THE ENTRY IS VALID
                    if ((!trCaptchaField.Visible) || (CaptchaImage.Authenticate(CaptchaInput.Text)))
                    {
                        // CAPTCHA IS HIDDEN OR VALIDATED, PROCEED WITH LOGIN ATTEMPT
                        if (Membership.ValidateUser(UserName.Text, Password.Text))
                        {
                            //LOGIN SUCCEEDED, MIGRATE USER IF NEEDED
                            int newUserId = loginUser.Id;
                            int oldUserId = AbleContext.Current.UserId;
                            if ((oldUserId != newUserId) && (newUserId != 0))
                            {
                                CommerceBuilder.Users.User.Migrate(AbleContext.Current.User, UserDataSource.Load(newUserId));
                                AbleContext.Current.UserId = newUserId;
                            }
                            //HANDLE LOGIN PROCESSING
                            if (RememberUserName.Checked)
                            {
                                HttpCookie cookie = new HttpCookie("UserName", UserName.Text);
                                cookie.Expires = DateTime.MaxValue;
                                Response.Cookies.Add(cookie);
                            }
                            else
                            {
                                Response.Cookies.Add(new HttpCookie("UserName", ""));
                            }
                            //CHECK FOR EXPIRED PASSWORDS
                            PasswordPolicy policy;
                            if (loginUser.IsAdmin)
                            {
                                policy = new MerchantPasswordPolicy();
                            }
                            else
                            {
                                policy = new CustomerPasswordPolicy();
                            }
                            if (policy.IsPasswordExpired(loginUser))
                            {
                                ShowPasswordExpired(policy, loginUser);
                            }
                            else
                            {
                                //REDIRECT TO THE STANDARD PAGE
                                FormsAuthentication.SetAuthCookie(UserName.Text, false);
                                Response.Redirect("EditBillAddress.aspx");
                            }
                        }
                        else
                        {
                            if (loginUser != null)
                            {
                                if (!loginUser.IsApproved)
                                {
                                    AccountDisabled.IsValid = false;
                                }
                                else
                                {
                                    PasswordPolicy policy;
                                    if (loginUser.IsAdmin)
                                    {
                                        policy = new MerchantPasswordPolicy();
                                    }
                                    else
                                    {
                                        policy = new CustomerPasswordPolicy();
                                    }
                                    int remainingTries = policy.MaxAttempts - loginUser.FailedPasswordAttemptCount;
                                    if (!loginUser.IsLockedOut && remainingTries > 0)
                                    {
                                        InvalidLogin.ErrorMessage += " You have {0} tries remaining.";
                                        InvalidLogin.ErrorMessage  = String.Format(InvalidLogin.ErrorMessage, remainingTries);
                                        InvalidLogin.IsValid       = false;
                                    }
                                    else
                                    {
                                        AccountLocked.ErrorMessage = String.Format(AccountLocked.ErrorMessage, policy.LockoutPeriod);
                                        AccountLocked.IsValid      = false;
                                    }
                                }
                            }
                            else
                            {
                                InvalidLogin.IsValid = false;
                            }
                        }
                    }
                    else
                    {
                        // CAPTCHA IS VISIBLE AND DID NOT AUTHENTICATE
                        trCaptchaImage.Visible = true;
                        trCaptchaField.Visible = true;
                        CustomValidator invalidInput = new CustomValidator();
                        invalidInput.ID = Guid.NewGuid().ToString();
                        invalidInput.ValidationGroup = "Login";
                        invalidInput.Text            = "*";
                        invalidInput.ErrorMessage    = "You did not input the verification number correctly.";
                        invalidInput.IsValid         = false;
                        phCaptchaValidators.Controls.Add(invalidInput);
                        CaptchaInput.Text = "";
                        Password.Attributes.Add("value", string.Empty);
                        RefreshCaptcha();
                    }
                }
                else
                {
                    // CAPTCHA IS REQUIRED BUT IT IS NOT DISPLAYED YET
                    trCaptchaField.Visible     = true;
                    trCaptchaImage.Visible     = true;
                    CaptchaImage.ChallengeText = StringHelper.RandomNumber(6);
                    CustomValidator needsCaptcha = new CustomValidator();
                    needsCaptcha.ID = "CaptchaRequiredValidator";
                    needsCaptcha.ValidationGroup = "Login";
                    needsCaptcha.Text            = "*";
                    needsCaptcha.ErrorMessage    = "Please type the verification number to log in.";
                    needsCaptcha.IsValid         = false;
                    phCaptchaValidators.Controls.Add(needsCaptcha);
                    Password.Attributes.Add("value", Password.Text);
                }
            }
            else
            {
                //THIS IS AN INVALID USER NAME
                InvalidLogin.IsValid = false;
            }
        }
Пример #23
0
        protected void ChangePasswordButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                //VERIFY THE GIVEN USERNAME IS VALID
                User user = UserDataSource.LoadForUserName(UserName.Text);
                if ((user != null) && !string.IsNullOrEmpty(UserName.Text) && !string.IsNullOrEmpty(_LastPasswordValue))
                {
                    //VERIFY CURRENT PASSWORD IS CORRECT
                    if (Membership.ValidateUser(UserName.Text, _LastPasswordValue))
                    {
                        //VERIFY THE NEW PASSWORD MEETS POLICY
                        PasswordPolicy policy;
                        if (user.IsAdmin)
                        {
                            policy = new MerchantPasswordPolicy();
                        }
                        else
                        {
                            policy = new CustomerPasswordPolicy();
                        }
                        PasswordTestResult result = policy.TestPasswordWithFeedback(user, NewPassword.Text);
                        if ((result & PasswordTestResult.Success) == PasswordTestResult.Success && !NewPassword.Text.Equals(_LastPasswordValue))
                        {
                            user.SetPassword(NewPassword.Text);
                            //LOGIN SUCCEEDED, REDIRECT
                            FormsAuthentication.RedirectFromLoginPage(UserName.Text, false);
                        }
                        else
                        {
                            //REDISPLAY THE PASSWORD REQUIREMENST
                            ShowPasswordExpired(policy, user);

                            //"Your new password did not meet the following minimum requirements:<br/>";
                            if ((result & PasswordTestResult.PasswordTooShort) == PasswordTestResult.PasswordTooShort)
                            {
                                AddPasswordExpiredValidator(string.Format(PasswordPolicyLength.Text, policy.MinLength));
                            }
                            if ((result & PasswordTestResult.RequireLower) == PasswordTestResult.RequireLower)
                            {
                                AddPasswordExpiredValidator("New password must contain at least one lowercase letter.<br/>");
                            }
                            if ((result & PasswordTestResult.RequireUpper) == PasswordTestResult.RequireUpper)
                            {
                                AddPasswordExpiredValidator("New password must contain at least one uppercase letter.<br/> ");
                            }
                            if ((result & PasswordTestResult.RequireNonAlpha) == PasswordTestResult.RequireNonAlpha)
                            {
                                AddPasswordExpiredValidator("New password must contain at least one non-letter.<br/> ");
                            }
                            if ((result & PasswordTestResult.RequireNumber) == PasswordTestResult.RequireNumber)
                            {
                                AddPasswordExpiredValidator("New password must contain at least one number.<br/> ");
                            }
                            if ((result & PasswordTestResult.RequireSymbol) == PasswordTestResult.RequireSymbol)
                            {
                                AddPasswordExpiredValidator("New password must contain at least one symbol.<br/> ");
                            }

                            if ((result & PasswordTestResult.PasswordHistoryLimitation) == PasswordTestResult.PasswordHistoryLimitation)
                            {
                                AddPasswordExpiredValidator("You have recently used this password.<br/>");
                            }
                            if (NewPassword.Text.Equals(_LastPasswordValue))
                            {
                                AddPasswordExpiredValidator("You new password must be different from your current password.<br/>");
                            }
                        }
                    }
                }
            }
        }