- MVCFormAuthentication_src.zip
- MVCFormAuthentication
- Demo.Base
- Demo.Web.Security
- Demo.Web.Tests
- Demo.Web
- App_Data
- bin
- Demo.Web.Security.dll
- Content
- Site.css
- themes
- base
- images
- ui-bg_flat_0_aaaaaa_40x100.png
- ui-bg_flat_75_ffffff_40x100.png
- ui-bg_glass_55_fbf9ee_1x400.png
- ui-bg_glass_65_ffffff_1x400.png
- ui-bg_glass_75_dadada_1x400.png
- ui-bg_glass_75_e6e6e6_1x400.png
- ui-bg_glass_95_fef1ec_1x400.png
- ui-bg_highlight-soft_75_cccccc_1x100.png
- ui-icons_222222_256x240.png
- ui-icons_2e83ff_256x240.png
- ui-icons_454545_256x240.png
- ui-icons_888888_256x240.png
- ui-icons_cd0a0a_256x240.png
- jquery-ui.css
- Controllers
- Demo.Web.cd
- Demo.Web.csproj
- Demo.Web.csproj.user
- Global.asax
- Global.asax.cs
- obj
- Debug
- DesignTimeResolveAssemblyReferencesInput.cache
- TempPE
- Properties
- Scripts
- ServiceInterfaces
- UnityDependencyLocator.cs
- Utilities
- ViewModels
- Views
- Web.config
- Web.Debug.config
- Web.Release.config
- WebRegistry.cs
- Library
- Microsoft.Practices.ServiceLocation.dll
- Microsoft.Practices.Unity.Configuration.dll
- Microsoft.Practices.Unity.dll
- Microsoft.Practices.Unity.Interception.Configuration.dll
- Microsoft.Practices.Unity.Interception.dll
- MVCFormAuthentication.sln
- MVCFormAuthentication.suo
- TestResults
- Henry_LAPTOP 2011-08-27 09_55_30.trx
- Henry_LAPTOP 2011-08-27 09_55_30
- Out
- Demo.Base.dll
- Demo.Base.pdb
- Demo.Web.dll
- Demo.Web.pdb
- demo.web.tests.dll
- demo.web.tests.dll.config
- Demo.Web.Tests.pdb
- Microsoft.Practices.ServiceLocation.dll
- Microsoft.Practices.Unity.Configuration.dll
- Microsoft.Practices.Unity.dll
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using System.Web.Security;
using System.Globalization;
namespace Demo.Web.Utilities
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public sealed class ValidatePasswordLengthAttribute : ValidationAttribute, IClientValidatable
{
private const string _defaultErrorMessage = "'{0}' must be at least {1} characters long.";
private readonly int _minCharacters = Membership.Provider.MinRequiredPasswordLength;
public ValidatePasswordLengthAttribute()
: base(_defaultErrorMessage)
{
}
public override string FormatErrorMessage(string name)
{
return String.Format(CultureInfo.CurrentCulture, ErrorMessageString,
name, _minCharacters);
}
public override bool IsValid(object value)
{
string valueAsString = value as string;
return (valueAsString != null && valueAsString.Length >= _minCharacters);
}
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
return new[]{
new ModelClientValidationStringLengthRule(FormatErrorMessage(metadata.GetDisplayName()), _minCharacters, int.MaxValue)
};
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.