/// <summary>
        /// When implemented in a class, provides metadata to the model metadata creation process.
        /// </summary>
        /// <param name="metadata">The model metadata.</param>
        public void OnMetadataCreated(ModelMetadata metadata)
        {
            const string ATTR = "lenrange";
            var          additionalMetadataValue = new ValidationAttributeMetadata(
                new Dictionary <string, string>
            {
                { "minlen", MinimumLength.ToString(CultureInfo.InvariantCulture) },
                { "maxlen", MaximumLength.ToString(CultureInfo.InvariantCulture) },
            }, ErrorMessageString);

            metadata.AdditionalValues.Add(ATTR, additionalMetadataValue);
        }
Exemplo n.º 2
0
 /// <summary>
 ///		Adds the HTML attributes and styles that need to be rendered for the control to the specified <see cref='System.Web.UI.HtmlTextWriter'/> object.
 /// </summary>
 /// <param name="writer">An <see cref='System.Web.UI.HtmlTextWriter'/> that represents the output stream to render HTML content on the client.</param>
 protected override void AddAttributesToRender(HtmlTextWriter writer)
 {
     base.AddAttributesToRender(writer);
     if (RenderUplevel)
     {
         string         id = ClientID;
         HtmlTextWriter expandoAttributeWriter = (EnableLegacyRendering) ? writer : null;
         AddExpandoAttribute(expandoAttributeWriter, id, "evaluationfunction", "LengthValidatorEvaluateIsValid", false);
         AddExpandoAttribute(expandoAttributeWriter, id, "minimumlength", MinimumLength.ToString());
         AddExpandoAttribute(expandoAttributeWriter, id, "minimumerrormessage", MinimumLengthErrorMessage);
         AddExpandoAttribute(expandoAttributeWriter, id, "maximumlength", MaximumLength.ToString());
         AddExpandoAttribute(expandoAttributeWriter, id, "maximumerrormessage", MaximumLengthErrorMessage);
     }
 }
Exemplo n.º 3
0
        private void AnalyzeMetaDescriptionAttribute(HtmlAttribute metaDescriptionAttribute)
        {
            var descriptionValue = metaDescriptionAttribute.Value;

            var resultRule = new ResultRule();

            if (string.IsNullOrWhiteSpace(descriptionValue))
            {
                resultRule.Alias = "no_description_value";
                resultRule.Type  = ResultType.Error;
            }
            else
            {
                descriptionValue = descriptionValue.Trim();

                if (descriptionValue.Length > MaximumLength)
                {
                    resultRule.Alias = "description_too_long";
                    resultRule.Type  = ResultType.Warning;
                }

                if (descriptionValue.Length < MinimumLength)
                {
                    resultRule.Alias = "description_too_short";
                    resultRule.Type  = ResultType.Warning;
                }
                else if (descriptionValue.Length < AcceptableLength)
                {
                    resultRule.Alias = "description_shorter_then_acceptable";
                    resultRule.Type  = ResultType.Hint;
                }

                if (descriptionValue.Length <= MaximumLength && descriptionValue.Length >= AcceptableLength)
                {
                    resultRule.Alias = "description_perfect";
                    resultRule.Type  = ResultType.Success;
                }
            }

            resultRule.Tokens.Add(MaximumLength.ToString());        // 0
            resultRule.Tokens.Add(MinimumLength.ToString());        // 1
            resultRule.Tokens.Add(AcceptableLength.ToString());     // 2

            AddResultRule(resultRule);
        }
Exemplo n.º 4
0
        private void ToggleControls()
        {
            valCorrectLength.Attributes["dpsw"]    = EMPTY_PASSWORD;
            valRequireNumbers.Attributes["dpsw"]   = EMPTY_PASSWORD;
            valRequireUppercase.Attributes["dpsw"] = EMPTY_PASSWORD;
            valRequireSymbols.Attributes["dpsw"]   = EMPTY_PASSWORD;

            // set empty password
            if (txtPassword.Text == "" && EditMode)
            {
                txtPassword.Attributes["value"]        = EMPTY_PASSWORD;
                txtConfirmPassword.Attributes["value"] = EMPTY_PASSWORD;
            }

            // enable/disable require validators
            valRequirePassword.Enabled        = ValidationEnabled;
            valRequireConfirmPassword.Enabled = ValidationEnabled;

            // require default length
            MinimumLength = Math.Max(MIN_PASSWORD_LENGTH, MinimumLength);

            // parse and enforce policy
            if (PolicyValue != null)
            {
                bool enabled            = false;
                int  minLength          = -1;
                int  maxLength          = -1;
                bool notEqualToUsername = false;

                try
                {
                    // parse settings
                    string[] parts = PolicyValue.Split(';');
                    enabled            = Utils.ParseBool(parts[0], false);
                    minLength          = Math.Max(Utils.ParseInt(parts[1], 0), MinimumLength);
                    maxLength          = Math.Max(Utils.ParseInt(parts[2], 0), MaximumLength);
                    MinimumUppercase   = Math.Max(Utils.ParseInt(parts[3], 0), MinimumUppercase);
                    MinimumNumbers     = Math.Max(Utils.ParseInt(parts[4], 0), MinimumNumbers);
                    MinimumSymbols     = Math.Max(Utils.ParseInt(parts[5], 0), MinimumSymbols);
                    notEqualToUsername = Utils.ParseBool(parts[6], false);
                }
                catch { /* skip */ }

                // apply policy
                if (enabled)
                {
                    // min length
                    if (minLength > 0)
                    {
                        MinimumLength            = minLength;
                        valCorrectLength.Enabled = true;
                        valCorrectLength.Attributes["minimumLength"] = MinimumLength.ToString();
                        valCorrectLength.ErrorMessage = String.Format(GetLocalizedString("CorrectLength.Text"), MinimumLength);
                    }

                    // max length
                    if (maxLength > 0)
                    {
                        MaximumLength                = maxLength;
                        txtPassword.MaxLength        = maxLength;
                        txtConfirmPassword.MaxLength = maxLength;
                    }

                    // numbers
                    if (MinimumNumbers > 0)
                    {
                        valRequireNumbers.Enabled = true;
                        valRequireNumbers.Attributes["minimumNumber"] = MinimumNumbers.ToString();
                        valRequireNumbers.ErrorMessage = String.Format(
                            GetLocalizedString("RequireNumbers.Text"), MinimumNumbers);
                    }

                    // UPPERCASE
                    if (MinimumUppercase > 0)
                    {
                        valRequireUppercase.Enabled = true;
                        valRequireUppercase.Attributes["minimumNumber"] = MinimumUppercase.ToString();
                        valRequireUppercase.ErrorMessage = String.Format(
                            GetLocalizedString("RequireUppercase.Text"), MinimumUppercase);
                    }

                    // symbols
                    if (MinimumSymbols > 0)
                    {
                        valRequireSymbols.Enabled = true;
                        valRequireSymbols.Attributes["minimumNumber"] = MinimumSymbols.ToString();
                        valRequireSymbols.ErrorMessage = String.Format(
                            GetLocalizedString("RequireSymbols.Text"), MinimumSymbols);
                    }
                } // if(enabled)
            }     // if (PolicyValue != null)

            // set min password generator
            lnkGenerate.NavigateUrl = String.Format("javascript:GeneratePassword('{0}', '{1}', '{2}', '{3}', '{4}', '{5}');",
                                                    MaximumLength, MinimumUppercase, MinimumNumbers, MinimumSymbols, txtPassword.ClientID, txtConfirmPassword.ClientID);
        }
 public bool Equals(StringLengthDescriptor other)
 => other != null && MinimumLength.Equals(other.MinimumLength) && MaximumLength.Equals(other.MaximumLength);