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
40 [TypeForwardedFrom ("System.Web, Version=2.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a")]
41 public abstract class MembershipProvider : ProviderBase
43 const string HELPER_TYPE_NAME = "System.Web.Security.MembershipHelper, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
45 internal static IMembershipHelper Helper {
46 get { return helper; }
48 static IMembershipHelper helper;
50 static readonly object validatingPasswordEvent = new object ();
52 EventHandlerList events = new EventHandlerList ();
53 public event MembershipValidatePasswordEventHandler ValidatingPassword {
54 add { events.AddHandler (validatingPasswordEvent, value); }
55 remove { events.RemoveHandler (validatingPasswordEvent, value); }
58 static MembershipProvider ()
60 Type type = Type.GetType (HELPER_TYPE_NAME, false);
65 helper = Activator.CreateInstance (type) as IMembershipHelper;
71 protected MembershipProvider ()
75 public abstract bool ChangePassword (string name, string oldPwd, string newPwd);
76 public abstract bool ChangePasswordQuestionAndAnswer (string name, string password, string newPwdQuestion, string newPwdAnswer);
77 public abstract MembershipUser CreateUser (string username, string password, string email, string pwdQuestion, string pwdAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status);
78 public abstract bool DeleteUser (string name, bool deleteAllRelatedData);
79 public abstract MembershipUserCollection FindUsersByEmail (string emailToMatch, int pageIndex, int pageSize, out int totalRecords);
80 public abstract MembershipUserCollection FindUsersByName (string nameToMatch, int pageIndex, int pageSize, out int totalRecords);
81 public abstract MembershipUserCollection GetAllUsers (int pageIndex, int pageSize, out int totalRecords);
82 public abstract int GetNumberOfUsersOnline ();
83 public abstract string GetPassword (string name, string answer);
84 public abstract MembershipUser GetUser (string name, bool userIsOnline);
85 public abstract MembershipUser GetUser (object providerUserKey, bool userIsOnline);
86 public abstract string GetUserNameByEmail (string email);
87 public abstract string ResetPassword (string name, string answer);
88 public abstract void UpdateUser (MembershipUser user);
89 public abstract bool ValidateUser (string name, string password);
90 public abstract bool UnlockUser (string userName);
92 public abstract string ApplicationName { get; set; }
93 public abstract bool EnablePasswordReset { get; }
94 public abstract bool EnablePasswordRetrieval { get; }
95 public abstract bool RequiresQuestionAndAnswer { get; }
96 public abstract int MaxInvalidPasswordAttempts { get; }
97 public abstract int MinRequiredNonAlphanumericCharacters { get; }
98 public abstract int MinRequiredPasswordLength { get; }
99 public abstract int PasswordAttemptWindow { get; }
100 public abstract MembershipPasswordFormat PasswordFormat { get; }
101 public abstract string PasswordStrengthRegularExpression { get; }
102 public abstract bool RequiresUniqueEmail { get; }
104 protected virtual void OnValidatingPassword (ValidatePasswordEventArgs args)
106 MembershipValidatePasswordEventHandler eh = events [validatingPasswordEvent] as MembershipValidatePasswordEventHandler;
111 protected virtual byte [] DecryptPassword (byte [] encodedPassword)
114 throw new PlatformNotSupportedException ("This method is not available.");
115 return helper.DecryptPassword (encodedPassword);
118 protected virtual byte[] EncryptPassword (byte[] password)
120 return EncryptPassword (password, MembershipPasswordCompatibilityMode.Framework20);
122 [MonoTODO ("Discover what actually is 4.0 password compatibility mode.")]
123 protected virtual byte[] EncryptPassword (byte[] password, MembershipPasswordCompatibilityMode legacyPasswordCompatibilityMode)
126 throw new PlatformNotSupportedException ("This method is not available.");
128 if (legacyPasswordCompatibilityMode == MembershipPasswordCompatibilityMode.Framework40)
129 throw new PlatformNotSupportedException ("Framework 4.0 password encryption mode is not supported at this time.");
131 return helper.EncryptPassword (password);