1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
//------------------------------------------------------------------------------
// <copyright file="MembershipProvider.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Security {
using System.Web;
using System.Security.Principal;
using System.Collections.Specialized;
using System.Security.Permissions;
using System.Globalization;
using System.Security.Cryptography;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Configuration.Provider;
using System.Text;
using System.Web.Configuration;
using System.Web.Util;
using System.Diagnostics.CodeAnalysis;
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
[TypeForwardedFrom("System.Web, Version=2.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public abstract class MembershipProvider : ProviderBase
{
//
// Property Section
//
// Public properties
public abstract bool EnablePasswordRetrieval { get; }
public abstract bool EnablePasswordReset { get; }
public abstract bool RequiresQuestionAndAnswer { get; }
public abstract string ApplicationName { get; set; }
public abstract int MaxInvalidPasswordAttempts { get; }
public abstract int PasswordAttemptWindow { get; }
public abstract bool RequiresUniqueEmail { get; }
public abstract MembershipPasswordFormat PasswordFormat { get; }
public abstract int MinRequiredPasswordLength { get; }
public abstract int MinRequiredNonAlphanumericCharacters { get; }
public abstract string PasswordStrengthRegularExpression { get; }
//
// Method Section
//
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "username", Justification="This version is required to maintain backwards binary compatibility")]
public abstract MembershipUser CreateUser( string username,
string password,
string email,
string passwordQuestion,
string passwordAnswer,
bool isApproved,
object providerUserKey,
out MembershipCreateStatus status );
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "username", Justification="This version is required to maintain backwards binary compatibility")]
public abstract bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer);
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "username", Justification="This version is required to maintain backwards binary compatibility")]
public abstract string GetPassword(string username, string answer);
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "username", Justification="This version is required to maintain backwards binary compatibility")]
public abstract bool ChangePassword(string username, string oldPassword, string newPassword);
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "username", Justification="This version is required to maintain backwards binary compatibility")]
public abstract string ResetPassword(string username, string answer);
public abstract void UpdateUser(MembershipUser user);
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "username", Justification="This version is required to maintain backwards binary compatibility")]
public abstract bool ValidateUser(string username, string password);
public abstract bool UnlockUser( string userName );
public abstract MembershipUser GetUser( object providerUserKey, bool userIsOnline );
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "username", Justification="This version is required to maintain backwards binary compatibility")]
public abstract MembershipUser GetUser(string username, bool userIsOnline);
// GetUser() can throw 1 type of exception:
// 1. ArgumentException is thrown if:
// A. Username is null, is empty, contains commas, or is longer than 256 characters
internal MembershipUser GetUser(string username, bool userIsOnline, bool throwOnError) {
MembershipUser user = null;
try {
user = GetUser(username, userIsOnline);
}
catch (ArgumentException) {
if (throwOnError) throw;
}
return user;
}
public abstract string GetUserNameByEmail(string email);
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "username", Justification="This version is required to maintain backwards binary compatibility")]
public abstract bool DeleteUser(string username, bool deleteAllRelatedData);
public abstract MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords);
public abstract int GetNumberOfUsersOnline();
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "username", Justification="This version is required to maintain backwards binary compatibility")]
public abstract MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords);
public abstract MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords);
protected virtual byte[] EncryptPassword( byte[] password)
{
return EncryptPassword(password, MembershipPasswordCompatibilityMode.Framework20);
}
protected virtual byte[] EncryptPassword( byte[] password, MembershipPasswordCompatibilityMode legacyPasswordCompatibilityMode)
{
if (SystemWebProxy.Membership.IsDecryptionKeyAutogenerated)
throw new ProviderException(ApplicationServicesStrings.Can_not_use_encrypted_passwords_with_autogen_keys);
return SystemWebProxy.Membership.EncryptOrDecryptData(true, password, legacyPasswordCompatibilityMode == MembershipPasswordCompatibilityMode.Framework20);
}
protected virtual byte[] DecryptPassword( byte[] encodedPassword )
{
if (SystemWebProxy.Membership.IsDecryptionKeyAutogenerated)
throw new ProviderException(ApplicationServicesStrings.Can_not_use_encrypted_passwords_with_autogen_keys);
try {
return SystemWebProxy.Membership.EncryptOrDecryptData(false, encodedPassword, false);
} catch {
if (!SystemWebProxy.Membership.UsingCustomEncryption)
throw;
}
return SystemWebProxy.Membership.EncryptOrDecryptData(false, encodedPassword, true);
}
//
// Event Section
//
public event MembershipValidatePasswordEventHandler ValidatingPassword
{
add
{
_EventHandler += value;
}
remove
{
_EventHandler -= value;
}
}
protected virtual void OnValidatingPassword( ValidatePasswordEventArgs e )
{
if( _EventHandler != null )
{
_EventHandler( this, e );
}
}
private MembershipValidatePasswordEventHandler _EventHandler;
}
}
|