Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@ -26,7 +26,6 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
namespace System.Web.Security {
@ -37,4 +36,3 @@ namespace System.Web.Security {
}
}
#endif

View File

@ -28,7 +28,6 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System.Collections.Specialized;
@ -217,5 +216,4 @@ namespace System.Web.Security {
}
}
}
#endif

View File

@ -27,7 +27,6 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
namespace System.Web.Security {
public sealed class AnonymousIdentificationEventArgs : EventArgs {
public AnonymousIdentificationEventArgs (HttpContext context)
@ -47,5 +46,4 @@ namespace System.Web.Security {
}
}
}
#endif

View File

@ -28,9 +28,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
namespace System.Web.Security {
public delegate void AnonymousIdentificationEventHandler (object sender, AnonymousIdentificationEventArgs e);
}
#endif

View File

@ -28,7 +28,6 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.ComponentModel;
@ -117,5 +116,4 @@ namespace System.Web.Security {
static AnonymousIdentificationSection Config = (AnonymousIdentificationSection) WebConfigurationManager.GetSection ("system.web/anonymousIdentification");
}
}
#endif

View File

@ -27,7 +27,6 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Collections.Generic;
using System.Text;
@ -86,4 +85,3 @@ namespace System.Web.Security
}
}
#endif

View File

@ -28,7 +28,6 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
namespace System.Web.Security {
public enum CookieProtection {
None = 0,
@ -37,5 +36,4 @@ namespace System.Web.Security {
All = 3
}
}
#endif

View File

@ -51,12 +51,10 @@ namespace System.Web.Security
throw new NotImplementedException ();
}
#if NET_2_0
[MonoTODO ("Not implemented")]
public static bool CheckFileAccessForUser (string virtualPath, IntPtr token, string verb)
{
throw new NotImplementedException ();
}
#endif
}
}

View File

@ -50,107 +50,6 @@ namespace System.Web.Security
static string authConfigPath = "system.web/authentication";
static string machineKeyConfigPath = "system.web/machineKey";
static object locker = new object ();
#if TARGET_J2EE
const string Forms_initialized = "Forms.initialized";
const string Forms_cookieName = "Forms.cookieName";
const string Forms_cookiePath = "Forms.cookiePath";
const string Forms_timeout = "Forms.timeout";
const string Forms_protection = "Forms.protection";
static bool initialized
{
get {
object o = AppDomain.CurrentDomain.GetData (Forms_initialized);
return o != null ? (bool) o : false;
}
set { AppDomain.CurrentDomain.SetData (Forms_initialized, value); }
}
static string cookieName
{
get { return (string) AppDomain.CurrentDomain.GetData (Forms_cookieName); }
set { AppDomain.CurrentDomain.SetData (Forms_cookieName, value); }
}
static string cookiePath
{
get { return (string) AppDomain.CurrentDomain.GetData (Forms_cookiePath); }
set { AppDomain.CurrentDomain.SetData (Forms_cookiePath, value); }
}
static int timeout
{
get {
object o = AppDomain.CurrentDomain.GetData (Forms_timeout);
return o != null ? (int) o : 0;
}
set { AppDomain.CurrentDomain.SetData (Forms_timeout, value); }
}
static FormsProtectionEnum protection
{
get { return (FormsProtectionEnum) AppDomain.CurrentDomain.GetData (Forms_protection); }
set { AppDomain.CurrentDomain.SetData (Forms_protection, value); }
}
const string Forms_requireSSL = "Forms.requireSSL";
const string Forms_slidingExpiration = "Forms.slidingExpiration";
static bool requireSSL
{
get {
object o = AppDomain.CurrentDomain.GetData (Forms_requireSSL);
return o != null ? (bool) o : false;
}
set { AppDomain.CurrentDomain.SetData (Forms_requireSSL, value); }
}
static bool slidingExpiration
{
get {
object o = AppDomain.CurrentDomain.GetData (Forms_slidingExpiration);
return o != null ? (bool) o : false;
}
set { AppDomain.CurrentDomain.SetData (Forms_slidingExpiration, value); }
}
const string Forms_cookie_domain = "Forms.cookie_domain";
const string Forms_cookie_mode = "Forms.cookie_mode";
const string Forms_cookies_supported = "Forms.cookies_supported";
const string Forms_default_url = "Forms.default_url";
const string Forms_enable_crossapp_redirects = "Forms.enable_crossapp_redirects";
const string Forms_login_url = "Forms.login_url";
static string cookie_domain
{
get { return (string) AppDomain.CurrentDomain.GetData (Forms_cookie_domain); }
set { AppDomain.CurrentDomain.SetData (Forms_cookie_domain, value); }
}
static HttpCookieMode cookie_mode
{
get { return (HttpCookieMode) AppDomain.CurrentDomain.GetData (Forms_cookie_mode); }
set { AppDomain.CurrentDomain.SetData (Forms_cookie_mode, value); }
}
static bool cookies_supported
{
get {
object o = AppDomain.CurrentDomain.GetData (Forms_cookies_supported);
return o != null ? (bool) o : false;
}
set { AppDomain.CurrentDomain.SetData (Forms_cookies_supported, value); }
}
static string default_url
{
get { return (string) AppDomain.CurrentDomain.GetData (Forms_default_url); }
set { AppDomain.CurrentDomain.SetData (Forms_default_url, value); }
}
static bool enable_crossapp_redirects
{
get {
object o = AppDomain.CurrentDomain.GetData (Forms_enable_crossapp_redirects);
return o != null ? (bool) o : false;
}
set { AppDomain.CurrentDomain.SetData (Forms_enable_crossapp_redirects, value); }
}
static string login_url
{
get { return (string) AppDomain.CurrentDomain.GetData (Forms_login_url); }
set { AppDomain.CurrentDomain.SetData (Forms_login_url, value); }
}
#else
static bool initialized;
static string cookieName;
static string cookiePath;
@ -164,14 +63,12 @@ namespace System.Web.Security
static string default_url;
static bool enable_crossapp_redirects;
static string login_url;
#endif
// same names and order used in xsp
static string [] indexFiles = { "index.aspx",
"Default.aspx",
"default.aspx",
"index.html",
"index.htm" };
#if NET_4_0
public static TimeSpan Timeout {
get; private set;
}
@ -194,7 +91,6 @@ namespace System.Web.Security
if (!String.IsNullOrEmpty (value))
default_url = value;
}
#endif
public FormsAuthentication ()
{
}
@ -428,9 +324,7 @@ namespace System.Web.Security
FormsAuthenticationConfiguration config = section.Forms;
cookieName = config.Name;
#if NET_4_0
Timeout = config.Timeout;
#endif
timeout = (int)config.Timeout.TotalMinutes;
cookiePath = config.Path;
protection = config.Protection;
@ -439,18 +333,14 @@ namespace System.Web.Security
cookie_domain = config.Domain;
cookie_mode = config.Cookieless;
cookies_supported = true; /* XXX ? */
#if NET_4_0
if (!String.IsNullOrEmpty (default_url))
default_url = MapUrl (default_url);
else
#endif
default_url = MapUrl(config.DefaultUrl);
enable_crossapp_redirects = config.EnableCrossAppRedirects;
#if NET_4_0
if (!String.IsNullOrEmpty (login_url))
login_url = MapUrl (login_url);
else
#endif
login_url = MapUrl(config.LoginUrl);
initialized = true;

View File

@ -43,11 +43,7 @@ namespace System.Web.Security
{
static readonly object authenticateEvent = new object ();
#if NET_2_0
AuthenticationSection _config = null;
#else
AuthConfig _config = null;
#endif
bool isConfigInitialized = false;
EventHandlerList events = new EventHandlerList ();
@ -60,11 +56,7 @@ namespace System.Web.Security
{
if(isConfigInitialized)
return;
#if NET_2_0
_config = (AuthenticationSection) WebConfigurationManager.GetSection ("system.web/authentication");
#else
_config = (AuthConfig) context.GetConfig ("system.web/authentication");
#endif
isConfigInitialized = true;
}
@ -98,17 +90,10 @@ namespace System.Web.Security
return;
}
#if NET_2_0
cookieName = _config.Forms.Name;
cookiePath = _config.Forms.Path;
loginPage = _config.Forms.LoginUrl;
slidingExpiration = _config.Forms.SlidingExpiration;
#else
cookieName = _config.CookieName;
cookiePath = _config.CookiePath;
loginPage = _config.LoginUrl;
slidingExpiration = _config.SlidingExpiration;
#endif
if (!VirtualPathUtility.IsRooted (loginPage))
loginPage = "~/" + loginPage;
@ -122,12 +107,10 @@ namespace System.Web.Security
context.SkipAuthorization = String.Compare (reqPath, loginPath, RuntimeHelpers.CaseInsensitive, Helpers.InvariantCulture) == 0;
#if NET_2_0
//TODO: need to check that the handler is System.Web.Handlers.AssemblyResourceLoader type
string filePath = context.Request.FilePath;
if (filePath.Length > 15 && String.CompareOrdinal ("WebResource.axd", 0, filePath, filePath.Length - 15, 15) == 0)
context.SkipAuthorization = true;
#endif
FormsAuthenticationEventArgs formArgs = new FormsAuthenticationEventArgs (context);
FormsAuthenticationEventHandler eh = events [authenticateEvent] as FormsAuthenticationEventHandler;
@ -180,18 +163,12 @@ namespace System.Web.Security
if (context.Response.StatusCode != 401 || context.Request.QueryString ["ReturnUrl"] != null)
return;
#if NET_4_5
if (context.Response.StatusCode == 401 && context.Response.SuppressFormsAuthenticationRedirect)
return;
#endif
string loginPage;
InitConfig (context);
#if NET_2_0
loginPage = _config.Forms.LoginUrl;
#else
loginPage = _config.LoginUrl;
#endif
if (_config == null || _config.Mode != AuthenticationMode.Forms)
return;

View File

@ -36,11 +36,7 @@ namespace System.Web.Security
[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
// attributes
[Serializable]
#if NET_4_0
public
#else
public sealed
#endif
class FormsIdentity : IIdentity
{
FormsAuthenticationTicket ticket;

View File

@ -30,6 +30,9 @@ using System;
using System.Web;
using System.Web.Configuration;
using System.Web.Util;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace System.Web.Security
{
@ -104,5 +107,59 @@ namespace System.Web.Security
return MachineKeySectionUtils.GetHexString (result);
}
public static byte[] Protect (byte[] userData, params string[] purposes)
{
if (userData == null)
throw new ArgumentNullException ("userData");
foreach (var purpose in purposes)
{
if (string.IsNullOrWhiteSpace (purpose))
throw new ArgumentException ("all purpose parameters must contain text");
}
var config = WebConfigurationManager.GetWebApplicationSection ("system.web/machineKey") as MachineKeySection;
var purposeJoined = string.Join (";", purposes);
var purposeBytes = GetHashed (purposeJoined);
var bytes = new byte [userData.Length + purposeBytes.Length];
purposeBytes.CopyTo (bytes, 0);
userData.CopyTo (bytes, purposeBytes.Length);
return MachineKeySectionUtils.Encrypt (config, bytes);
}
public static byte[] Unprotect (byte[] protectedData, params string[] purposes)
{
if (protectedData == null)
throw new ArgumentNullException ("protectedData");
foreach (var purpose in purposes) {
if (string.IsNullOrWhiteSpace (purpose))
throw new ArgumentException ("all purpose parameters must contain text");
}
var config = WebConfigurationManager.GetWebApplicationSection ("system.web/machineKey") as MachineKeySection;
var purposeJoined = string.Join (";", purposes);
var purposeBytes = GetHashed (purposeJoined);
var unprotected = MachineKeySectionUtils.Decrypt (config, protectedData);
for (int i = 0; i < purposeBytes.Length; i++) {
if (purposeBytes [i] != unprotected [i])
throw new CryptographicException ();
}
var dataLength = unprotected.Length - purposeBytes.Length;
var result = new byte [dataLength];
Array.Copy (unprotected, purposeBytes.Length, result, 0, dataLength);
return result;
}
static byte[] GetHashed (string purposes)
{
using (var hash = SHA512.Create ()) {
var bytes = Encoding.UTF8.GetBytes (purposes);
return hash.ComputeHash (bytes, 0, bytes.Length);
}
}
}
}

View File

@ -30,7 +30,6 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System.Collections;
using System.Collections.Specialized;
using System.Text;
@ -42,57 +41,6 @@ namespace System.Web.Security
{
public static class Membership
{
#if TARGET_J2EE
const string Membership_providers = "Membership.providers";
static MembershipProviderCollection providers {
get {
object o = AppDomain.CurrentDomain.GetData (Membership_providers);
if (o == null) {
lock (AppDomain.CurrentDomain) {
o = AppDomain.CurrentDomain.GetData (Membership_providers);
if (o == null) {
MembershipSection section = (MembershipSection) WebConfigurationManager.GetSection ("system.web/membership");
MembershipProviderCollection local_providers = new MembershipProviderCollection ();
ProvidersHelper.InstantiateProviders (section.Providers, local_providers, typeof (MembershipProvider));
AppDomain.CurrentDomain.SetData (Membership_providers, local_providers);
o = local_providers;
}
}
}
return (MembershipProviderCollection) o;
}
}
static MembershipProvider provider {
get {
MembershipSection section = (MembershipSection) WebConfigurationManager.GetSection ("system.web/membership");
MembershipProvider p = providers [section.DefaultProvider];
if (p == null)
throw new ConfigurationErrorsException ("Default Membership Provider could not be found: Cannot instantiate provider: '" + section.DefaultProvider + "'.");
return p;
}
}
static int onlineTimeWindow {
get {
MembershipSection section = (MembershipSection) WebConfigurationManager.GetSection ("system.web/membership");
return (int) section.UserIsOnlineTimeWindow.TotalMinutes;
}
}
static string hashAlgorithmType {
get {
MembershipSection section = (MembershipSection) WebConfigurationManager.GetSection ("system.web/membership");
string ret = section.HashAlgorithmType;
if (ret == String.Empty) {
MachineKeySection mks = WebConfigurationManager.GetSection ("system.web/machineKey") as MachineKeySection;
return mks.Validation;
}
return ret;
}
}
#else
static MembershipProviderCollection providers;
static MembershipProvider provider;
static int onlineTimeWindow;
@ -119,7 +67,6 @@ namespace System.Web.Security
if (String.IsNullOrEmpty (hashAlgorithmType))
hashAlgorithmType = "SHA1";
}
#endif
public static MembershipUser CreateUser (string username, string password)
{
@ -370,5 +317,4 @@ namespace System.Web.Security
}
}
}
#endif

View File

@ -1,53 +0,0 @@
//
// System.Web.Security.MembershipCreateStatus
//
// Authors:
// Ben Maurer (bmaurer@users.sourceforge.net)
//
// (C) 2003 Ben Maurer
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.CompilerServices;
namespace System.Web.Security
{
#if NET_4_0
[TypeForwardedFrom ("System.Web, Version=2.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a")]
#endif
public enum MembershipCreateStatus
{
Success,
InvalidUserName,
InvalidPassword,
InvalidQuestion,
InvalidAnswer,
InvalidEmail,
DuplicateUserName,
DuplicateEmail,
UserRejected,
InvalidProviderUserKey,
DuplicateProviderUserKey,
ProviderError
}
}

View File

@ -1,79 +0,0 @@
//
// System.Web.Security.MembershipCreateUserException
//
// Authors:
// Ben Maurer (bmaurer@users.sourceforge.net)
//
// (C) 2003 Ben Maurer
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Runtime.Serialization;
using System.Runtime.CompilerServices;
namespace System.Web.Security
{
#if NET_4_0
[TypeForwardedFrom ("System.Web, Version=2.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a")]
#endif
[Serializable]
public class MembershipCreateUserException : Exception
{
MembershipCreateStatus statusCode;
public MembershipCreateUserException ()
{
}
public MembershipCreateUserException (string message): base (message)
{
}
public MembershipCreateUserException (string message, Exception innerException): base (message, innerException)
{
}
protected MembershipCreateUserException (SerializationInfo info, StreamingContext context): base (info, context)
{
info.AddValue ("statusCode", statusCode);
}
public MembershipCreateUserException (MembershipCreateStatus statusCode) : base (statusCode.ToString ())
{
this.statusCode = statusCode;
}
public override void GetObjectData (SerializationInfo info, StreamingContext ctx)
{
base.GetObjectData (info, ctx);
statusCode = (MembershipCreateStatus) info.GetValue ("statusCode", typeof(MembershipCreateStatus));
}
public MembershipCreateStatus StatusCode {
get { return statusCode; }
}
}
}

View File

@ -36,9 +36,7 @@ using System.Web.Util;
namespace System.Web.Security
{
sealed class MembershipHelper
#if NET_4_0
: IMembershipHelper
#endif
{
internal const int SALT_BYTES = 16;

View File

@ -0,0 +1,110 @@
//
// System.Web.Security.MembershipPasswordAttribute
//
// Authors:
// Martin Thwaites (github@my2cents.co.uk)
//
// (C) 2014 Martin Thwaites
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text.RegularExpressions;
namespace System.Web.Security
{
[AttributeUsageAttribute (AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter, AllowMultiple = false)]
public class MembershipPasswordAttribute : ValidationAttribute
{
public string MinNonAlphanumericCharactersError { get; set; }
public string MinPasswordLengthError { get; set; }
public int MinRequiredNonAlphanumericCharacters { get; set; }
public int MinRequiredPasswordLength { get; set; }
public string PasswordStrengthError { get; set; }
public string PasswordStrengthRegularExpression { get; set; }
public Type ResourceType { get; set; }
public MembershipPasswordAttribute ()
{
if (Membership.Provider != null)
{
MinRequiredNonAlphanumericCharacters = Membership.Provider.MinRequiredNonAlphanumericCharacters;
MinRequiredPasswordLength = Membership.Provider.MinRequiredPasswordLength;
PasswordStrengthRegularExpression = Membership.Provider.PasswordStrengthRegularExpression;
}
else
{
MinRequiredPasswordLength = 7;
MinRequiredNonAlphanumericCharacters = 1;
PasswordStrengthRegularExpression = @"(?=.{6,})(?=(.*\d){1,})(?=(.*\W){1,})";
}
MinNonAlphanumericCharactersError = "The '{0}' field is an invalid password. Password must have {1} or more non-alphanumeric characters.";
MinPasswordLengthError = "The '{0}' field is an invalid password. Password must have {1} or more characters.";
PasswordStrengthError = "The '{0}' field is an invalid password. It does not meet the password strength requirements";
ErrorMessage = "The field {0} is invalid.";
}
protected override ValidationResult IsValid (object value, ValidationContext validationContext)
{
var password = value as string;
var isError = false;
if (string.IsNullOrEmpty(password))
return null;
var errorMessage = string.Empty;
var parameter = 0;
var pattern = new Regex (@"\W|_");
if (MinRequiredPasswordLength > 0 &&
password.Length < MinRequiredPasswordLength) {
errorMessage = MinPasswordLengthError;
parameter = MinRequiredPasswordLength;
isError = true;
}
if (!isError && MinRequiredNonAlphanumericCharacters > 0 &&
pattern.Matches (password).Count < MinRequiredNonAlphanumericCharacters) {
errorMessage = MinNonAlphanumericCharactersError;
parameter = MinRequiredNonAlphanumericCharacters;
isError = true;
}
if (!isError && !string.IsNullOrEmpty (PasswordStrengthRegularExpression) &&
new Regex (PasswordStrengthRegularExpression).IsMatch (password)) {
errorMessage = PasswordStrengthError;
isError = true;
}
if (isError) {
if (validationContext == null)
return new ValidationResult("error");
return new ValidationResult (
string.Format (errorMessage, validationContext.DisplayName, parameter),
new[] {validationContext.MemberName});
}
return ValidationResult.Success;
}
}
}

View File

@ -1,53 +0,0 @@
//
// System.Web.Security.MembershipPasswordException
//
// Authors:
// Ben Maurer (bmaurer@users.sourceforge.net)
//
// (C) 2003 Ben Maurer
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Runtime.Serialization;
using System.Runtime.CompilerServices;
namespace System.Web.Security
{
#if NET_4_0
[TypeForwardedFrom ("System.Web, Version=2.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a")]
#endif
[Serializable]
public class MembershipPasswordException : Exception
{
public MembershipPasswordException () : base () {}
public MembershipPasswordException (string message) : base (message) {}
public MembershipPasswordException (string message, Exception innerException) : base (message, innerException) {}
protected MembershipPasswordException (SerializationInfo info, StreamingContext context): base (info, context)
{
}
}
}

View File

@ -1,45 +0,0 @@
//
// System.Web.Security.MembershipPasswordFormat
//
// Authors:
// Ben Maurer (bmaurer@users.sourceforge.net)
//
// (C) 2003 Ben Maurer
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.CompilerServices;
namespace System.Web.Security
{
#if NET_4_0
[TypeForwardedFrom ("System.Web, Version=2.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a")]
#endif
public enum MembershipPasswordFormat
{
Clear = 0,
Hashed = 1,
Encrypted = 2
}
}

View File

@ -1,155 +0,0 @@
//
// System.Web.Security.MembershipProvider
//
// Authors:
// Ben Maurer (bmaurer@users.sourceforge.net)
// Lluis Sanchez Gual (lluis@novell.com)
//
// (C) 2003 Ben Maurer
// Copyright (C) 2005-2010 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.ComponentModel;
using System.Configuration.Provider;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Web.Configuration;
namespace System.Web.Security
{
#if NET_4_0
[TypeForwardedFrom ("System.Web, Version=2.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a")]
#endif
public abstract class MembershipProvider : ProviderBase
{
#if NET_4_0
const string HELPER_TYPE_NAME = "System.Web.Security.MembershipHelper, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
internal static IMembershipHelper Helper {
get { return helper; }
}
static IMembershipHelper helper;
#else
static MembershipHelper helper;
#endif
static readonly object validatingPasswordEvent = new object ();
EventHandlerList events = new EventHandlerList ();
public event MembershipValidatePasswordEventHandler ValidatingPassword {
add { events.AddHandler (validatingPasswordEvent, value); }
remove { events.RemoveHandler (validatingPasswordEvent, value); }
}
static MembershipProvider ()
{
#if NET_4_0
Type type = Type.GetType (HELPER_TYPE_NAME, false);
if (type == null)
return;
try {
helper = Activator.CreateInstance (type) as IMembershipHelper;
} catch {
// ignore
}
#else
helper = new MembershipHelper ();
#endif
}
protected MembershipProvider ()
{
}
public abstract bool ChangePassword (string name, string oldPwd, string newPwd);
public abstract bool ChangePasswordQuestionAndAnswer (string name, string password, string newPwdQuestion, string newPwdAnswer);
public abstract MembershipUser CreateUser (string username, string password, string email, string pwdQuestion, string pwdAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status);
public abstract bool DeleteUser (string name, bool deleteAllRelatedData);
public abstract MembershipUserCollection FindUsersByEmail (string emailToMatch, int pageIndex, int pageSize, out int totalRecords);
public abstract MembershipUserCollection FindUsersByName (string nameToMatch, int pageIndex, int pageSize, out int totalRecords);
public abstract MembershipUserCollection GetAllUsers (int pageIndex, int pageSize, out int totalRecords);
public abstract int GetNumberOfUsersOnline ();
public abstract string GetPassword (string name, string answer);
public abstract MembershipUser GetUser (string name, bool userIsOnline);
public abstract MembershipUser GetUser (object providerUserKey, bool userIsOnline);
public abstract string GetUserNameByEmail (string email);
public abstract string ResetPassword (string name, string answer);
public abstract void UpdateUser (MembershipUser user);
public abstract bool ValidateUser (string name, string password);
public abstract bool UnlockUser (string userName);
public abstract string ApplicationName { get; set; }
public abstract bool EnablePasswordReset { get; }
public abstract bool EnablePasswordRetrieval { get; }
public abstract bool RequiresQuestionAndAnswer { get; }
public abstract int MaxInvalidPasswordAttempts { get; }
public abstract int MinRequiredNonAlphanumericCharacters { get; }
public abstract int MinRequiredPasswordLength { get; }
public abstract int PasswordAttemptWindow { get; }
public abstract MembershipPasswordFormat PasswordFormat { get; }
public abstract string PasswordStrengthRegularExpression { get; }
public abstract bool RequiresUniqueEmail { get; }
protected virtual void OnValidatingPassword (ValidatePasswordEventArgs args)
{
MembershipValidatePasswordEventHandler eh = events [validatingPasswordEvent] as MembershipValidatePasswordEventHandler;
if (eh != null)
eh (this, args);
}
protected virtual byte [] DecryptPassword (byte [] encodedPassword)
{
#if NET_4_0
if (helper == null)
throw new PlatformNotSupportedException ("This method is not available.");
#endif
return helper.DecryptPassword (encodedPassword);
}
protected virtual byte[] EncryptPassword (byte[] password)
{
#if NET_4_0
return EncryptPassword (password, MembershipPasswordCompatibilityMode.Framework20);
#else
return helper.EncryptPassword (password);
#endif
}
#if NET_4_0
[MonoTODO ("Discover what actually is 4.0 password compatibility mode.")]
protected virtual byte[] EncryptPassword (byte[] password, MembershipPasswordCompatibilityMode legacyPasswordCompatibilityMode)
{
if (helper == null)
throw new PlatformNotSupportedException ("This method is not available.");
if (legacyPasswordCompatibilityMode == MembershipPasswordCompatibilityMode.Framework40)
throw new PlatformNotSupportedException ("Framework 4.0 password encryption mode is not supported at this time.");
return helper.EncryptPassword (password);
}
#endif
}
}

Some files were not shown because too many files have changed in this diff Show More