2 // System.Web.Security.MembershipProvider
5 // Ben Maurer (bmaurer@users.sourceforge.net)
6 // Lluis Sanchez Gual (lluis@novell.com)
9 // Copyright (C) 2005-2010 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.ComponentModel;
32 using System.Configuration.Provider;
33 using System.Reflection;
34 using System.Runtime.CompilerServices;
36 using System.Web.Configuration;
38 namespace System.Web.Security
41 [TypeForwardedFrom ("System.Web, Version=2.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a")]
43 public abstract class MembershipProvider : ProviderBase
46 const string HELPER_TYPE_NAME = "System.Web.Security.MembershipHelper, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
48 internal static IMembershipHelper Helper {
49 get { return helper; }
51 static IMembershipHelper helper;
53 static MembershipHelper helper;
56 static readonly object validatingPasswordEvent = new object ();
58 EventHandlerList events = new EventHandlerList ();
59 public event MembershipValidatePasswordEventHandler ValidatingPassword {
60 add { events.AddHandler (validatingPasswordEvent, value); }
61 remove { events.RemoveHandler (validatingPasswordEvent, value); }
64 static MembershipProvider ()
67 Type type = Type.GetType (HELPER_TYPE_NAME, false);
72 helper = Activator.CreateInstance (type) as IMembershipHelper;
77 helper = new MembershipHelper ();
81 protected MembershipProvider ()
85 public abstract bool ChangePassword (string name, string oldPwd, string newPwd);
86 public abstract bool ChangePasswordQuestionAndAnswer (string name, string password, string newPwdQuestion, string newPwdAnswer);
87 public abstract MembershipUser CreateUser (string username, string password, string email, string pwdQuestion, string pwdAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status);
88 public abstract bool DeleteUser (string name, bool deleteAllRelatedData);
89 public abstract MembershipUserCollection FindUsersByEmail (string emailToMatch, int pageIndex, int pageSize, out int totalRecords);
90 public abstract MembershipUserCollection FindUsersByName (string nameToMatch, int pageIndex, int pageSize, out int totalRecords);
91 public abstract MembershipUserCollection GetAllUsers (int pageIndex, int pageSize, out int totalRecords);
92 public abstract int GetNumberOfUsersOnline ();
93 public abstract string GetPassword (string name, string answer);
94 public abstract MembershipUser GetUser (string name, bool userIsOnline);
95 public abstract MembershipUser GetUser (object providerUserKey, bool userIsOnline);
96 public abstract string GetUserNameByEmail (string email);
97 public abstract string ResetPassword (string name, string answer);
98 public abstract void UpdateUser (MembershipUser user);
99 public abstract bool ValidateUser (string name, string password);
100 public abstract bool UnlockUser (string userName);
102 public abstract string ApplicationName { get; set; }
103 public abstract bool EnablePasswordReset { get; }
104 public abstract bool EnablePasswordRetrieval { get; }
105 public abstract bool RequiresQuestionAndAnswer { get; }
106 public abstract int MaxInvalidPasswordAttempts { get; }
107 public abstract int MinRequiredNonAlphanumericCharacters { get; }
108 public abstract int MinRequiredPasswordLength { get; }
109 public abstract int PasswordAttemptWindow { get; }
110 public abstract MembershipPasswordFormat PasswordFormat { get; }
111 public abstract string PasswordStrengthRegularExpression { get; }
112 public abstract bool RequiresUniqueEmail { get; }
114 protected virtual void OnValidatingPassword (ValidatePasswordEventArgs args)
116 MembershipValidatePasswordEventHandler eh = events [validatingPasswordEvent] as MembershipValidatePasswordEventHandler;
121 protected virtual byte [] DecryptPassword (byte [] encodedPassword)
125 throw new PlatformNotSupportedException ("This method is not available.");
127 return helper.DecryptPassword (encodedPassword);
130 protected virtual byte[] EncryptPassword (byte[] password)
133 return EncryptPassword (password, MembershipPasswordCompatibilityMode.Framework20);
135 return helper.EncryptPassword (password);
139 [MonoTODO ("Discover what actually is 4.0 password compatibility mode.")]
140 protected virtual byte[] EncryptPassword (byte[] password, MembershipPasswordCompatibilityMode legacyPasswordCompatibilityMode)
143 throw new PlatformNotSupportedException ("This method is not available.");
145 if (legacyPasswordCompatibilityMode == MembershipPasswordCompatibilityMode.Framework40)
146 throw new PlatformNotSupportedException ("Framework 4.0 password encryption mode is not supported at this time.");
148 return helper.EncryptPassword (password);