C# Класс Phun.Security.PhunSimpleMembershipProvider

Copied from here: https://github.com/ASP-NET-MVC/aspnetwebstack/blob/master/src/WebMatrix.WebData/SimpleMembershipProvider.cs Apache License copyright 2.0 blah blah... to support more database engine. This is one horribly big file. Somebody should be smacked with a large trout. Half way through I feel like a coding monkey, the rest of the CMS feel like it's not even this big. GRRRRR!!!!
Наследование: WebMatrix.WebData.ExtendedMembershipProvider
Показать файл Открыть проект Примеры использования класса

Private Properties

Свойство Тип Описание
CheckPassword bool
ConnectToDatabase DapperContext
CreateOAuthTokenTableIfNeeded void
DeleteUserAndAccountInternal bool
GenerateToken string
GenerateToken string
GetHashedPassword string
GetPasswordFailureCount int
SetPassword bool
ValidateUserTable void
VerifyUserNameHasConfirmedAccount int

Открытые методы

Метод Описание
ChangePassword ( string username, string oldPassword, string newPassword ) : bool

Processes a request to update the password for a membership user.

ChangePasswordQuestionAndAnswer ( string username, string password, string newPasswordQuestion, string newPasswordAnswer ) : bool

Processes a request to update the password question and answer for a membership user.

ConfirmAccount ( string accountConfirmationToken ) : bool

Sets the confirmed flag for the username if it is correct.

Inherited from ExtendedMembershipProvider ==> Simple Membership MUST be enabled to use this method. There is a tiny possibility where this method fails to work correctly. Two or more users could be assigned the same token but specified using different cases. A workaround for this would be to use the overload that accepts both the user name and confirmation token.

ConfirmAccount ( string userName, string accountConfirmationToken ) : bool

Sets the confirmed flag for the username if it is correct.

Inherited from ExtendedMembershipProvider ==> Simple Membership MUST be enabled to use this method

CreateAccount ( string userName, string password, bool requireConfirmationToken ) : string

When overridden in a derived class, creates a new user account using the specified user name and password, optionally requiring that the new account must be confirmed before the account is available for use.

CreateOrUpdateOAuthAccount ( string provider, string providerUserId, string userName ) : void

Creates the or update O auth account.

CreateUser ( string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, MembershipCreateStatus &status ) : System.Web.Security.MembershipUser

Adds a new membership user to the data source.

CreateUserAndAccount ( string userName, string password, bool requireConfirmation, object>.IDictionary values ) : string

When overridden in a derived class, creates a new user profile and a new membership account.

DeleteAccount ( string userName ) : bool

When overridden in a derived class, deletes the specified membership account.

DeleteOAuthAccount ( string provider, string providerUserId ) : void

When overridden in a derived class, deletes the OAuth or OpenID account with the specified provider name and provider user ID.

DeleteOAuthToken ( string token ) : void

Deletes the OAuth token from the backing store from the database.

DeleteUser ( string userName, bool deleteAllRelatedData ) : bool

Removes a user from the membership data source.

FindUsersByEmail ( string emailToMatch, int pageIndex, int pageSize, int &totalRecords ) : System.Web.Security.MembershipUserCollection

Gets a collection of membership users where the e-mail address contains the specified e-mail address to match.

FindUsersByName ( string usernameToMatch, int pageIndex, int pageSize, int &totalRecords ) : System.Web.Security.MembershipUserCollection

Gets a collection of membership users where the user name contains the specified user name to match.

GeneratePasswordResetToken ( string userName, int tokenExpirationInMinutesFromNow ) : string

When overridden in a derived class, generates a password reset token that can be sent to a user in email.

GetAccountsForUser ( string userName ) : ICollection

When overridden in a derived class, returns all OAuth membership accounts associated with the specified user name.

GetAllUsers ( int pageIndex, int pageSize, int &totalRecords ) : System.Web.Security.MembershipUserCollection

Gets a collection of all the users in the data source in pages of data.

GetCreateDate ( string userName ) : System.DateTime

When overridden in a derived class, returns the date and time when the specified user account was created.

GetLastPasswordFailureDate ( string userName ) : System.DateTime

When overridden in a derived class, returns the date and time when an incorrect password was most recently entered for the specified user account.

GetNumberOfUsersOnline ( ) : int

Gets the number of users currently accessing the application.

GetOAuthTokenSecret ( string token ) : string

Gets the O auth token secret.

GetPassword ( string username, string answer ) : string

Gets the password for the specified user name from the data source.

GetPasswordChangedDate ( string userName ) : System.DateTime

When overridden in a derived class, returns the date and time when the password was most recently changed for the specified membership account.

GetPasswordFailuresSinceLastSuccess ( string userName ) : int

When overridden in a derived class, returns the number of times that the password for the specified user account was incorrectly entered since the most recent successful login or since the user account was created.

GetUser ( object providerUserKey, bool userIsOnline ) : System.Web.Security.MembershipUser

Gets user information from the data source based on the unique identifier for the membership user. Provides an option to update the last-activity date/time stamp for the user.

GetUser ( string username, bool userIsOnline ) : System.Web.Security.MembershipUser

Gets information from the data source for a user. Provides an option to update the last-activity date/time stamp for the user.

GetUserId ( string userName ) : int

Gets the user id.

GetUserIdFromOAuth ( string provider, string providerUserId ) : int

When overridden in a derived class, returns the user ID for the specified OAuth or OpenID provider and provider user ID.

GetUserIdFromPasswordResetToken ( string token ) : int

When overridden in a derived class, returns an ID for a user based on a password reset token.

GetUserNameByEmail ( string email ) : string

Gets the user name associated with the specified e-mail address.

GetUserNameFromId ( int userId ) : string

Returns the user name that is associated with the specified user ID.

HasLocalAccount ( int userId ) : bool

Determines whether there exists a local account (as opposed to OAuth account) with the specified userId.

Initialize ( string name, NameValueCollection config ) : void

Initializes the provider.

IsConfirmed ( string userName ) : bool

When overridden in a derived class, returns a value that indicates whether the user account has been confirmed by the provider.

PhunSimpleMembershipProvider ( ) : System

Initializes a new instance of the PhunSimpleMembershipProvider class.

PhunSimpleMembershipProvider ( MembershipProvider previousProvider ) : System

Initializes a new instance of the PhunSimpleMembershipProvider class.

ReplaceOAuthRequestTokenWithAccessToken ( string requestToken, string accessToken, string accessTokenSecret ) : void

Replaces the request token with access token and secret.

ResetPassword ( string username, string answer ) : string

Resets a user's password to a new, automatically generated password.

ResetPasswordWithToken ( string token, string newPassword ) : bool

When overridden in a derived class, resets a password after verifying that the specified password reset token is valid.

StoreOAuthRequestToken ( string requestToken, string requestTokenSecret ) : void

Stores the O auth request token.

UnlockUser ( string userName ) : bool

Clears a lock so that the membership user can be validated.

UpdateUser ( System.Web.Security.MembershipUser user ) : void

Updates information about a user in the data source.

ValidateUser ( string username, string password ) : bool

Verifies that the specified user name and password exist in the data source.

Защищенные методы

Метод Описание
CreateTablesIfNeeded ( ) : void

Creates the tables if needed.

GetUserId ( DapperContext db, string userTableName, string userNameColumn, string userIdColumn, string userName ) : int

Gets the user id.

VerifyInitialized ( ) : void

Verifies the initialized.

Приватные методы

Метод Описание
CheckPassword ( DapperContext db, int userId, string password ) : bool

Checks the password.

ConnectToDatabase ( ) : DapperContext

Connects to database.

CreateOAuthTokenTableIfNeeded ( DapperContext db ) : void

Creates the O auth token table if needed.

DeleteUserAndAccountInternal ( string userName ) : bool

Deletes the user and account internal.

GenerateToken ( ) : string

Generates the token.

GenerateToken ( RandomNumberGenerator generator ) : string

Generates the token.

GetHashedPassword ( DapperContext db, int userId ) : string

Gets the hashed password.

GetPasswordFailureCount ( DapperContext db, int userId ) : int

Gets the password failures since last success.

SetPassword ( DapperContext db, int userId, string newPassword ) : bool

Sets the password.

ValidateUserTable ( ) : void

Validates the user table.

VerifyUserNameHasConfirmedAccount ( DapperContext db, string username, bool throwException ) : int

Verifies the user name has confirmed account.

Описание методов

ChangePassword() публичный Метод

Processes a request to update the password for a membership user.
/// username /// or /// oldPassword /// or /// newPassword ///
public ChangePassword ( string username, string oldPassword, string newPassword ) : bool
username string The user to update the password for.
oldPassword string The current password for the specified user.
newPassword string The new password for the specified user.
Результат bool

ChangePasswordQuestionAndAnswer() публичный Метод

Processes a request to update the password question and answer for a membership user.
public ChangePasswordQuestionAndAnswer ( string username, string password, string newPasswordQuestion, string newPasswordAnswer ) : bool
username string The user to change the password question and answer for.
password string The password for the specified user.
newPasswordQuestion string The new password question for the specified user.
newPasswordAnswer string The new password answer for the specified user.
Результат bool

ConfirmAccount() публичный Метод

Sets the confirmed flag for the username if it is correct.
Inherited from ExtendedMembershipProvider ==> Simple Membership MUST be enabled to use this method. There is a tiny possibility where this method fails to work correctly. Two or more users could be assigned the same token but specified using different cases. A workaround for this would be to use the overload that accepts both the user name and confirmation token.
public ConfirmAccount ( string accountConfirmationToken ) : bool
accountConfirmationToken string A confirmation token to pass to the authentication provider.
Результат bool

ConfirmAccount() публичный Метод

Sets the confirmed flag for the username if it is correct.
Inherited from ExtendedMembershipProvider ==> Simple Membership MUST be enabled to use this method
public ConfirmAccount ( string userName, string accountConfirmationToken ) : bool
userName string The user name.
accountConfirmationToken string A confirmation token to pass to the authentication provider.
Результат bool

CreateAccount() публичный Метод

When overridden in a derived class, creates a new user account using the specified user name and password, optionally requiring that the new account must be confirmed before the account is available for use.
///
public CreateAccount ( string userName, string password, bool requireConfirmationToken ) : string
userName string The user name.
password string The password.
requireConfirmationToken bool (Optional) true to specify that the account must be confirmed; otherwise, false. The default is false.
Результат string

CreateOrUpdateOAuthAccount() публичный Метод

Creates the or update O auth account.
public CreateOrUpdateOAuthAccount ( string provider, string providerUserId, string userName ) : void
provider string The provider.
providerUserId string The provider user id.
userName string Name of the user.
Результат void

CreateTablesIfNeeded() защищенный Метод

Creates the tables if needed.
protected CreateTablesIfNeeded ( ) : void
Результат void

CreateUser() публичный Метод

Adds a new membership user to the data source.
public CreateUser ( string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, MembershipCreateStatus &status ) : System.Web.Security.MembershipUser
username string The user name for the new user.
password string The password for the new user.
email string The e-mail address for the new user.
passwordQuestion string The password question for the new user.
passwordAnswer string The password answer for the new user
isApproved bool Whether or not the new user is approved to be validated.
providerUserKey object The unique identifier from the membership data source for the user.
status MembershipCreateStatus A enumeration value indicating whether the user was created successfully.
Результат System.Web.Security.MembershipUser

CreateUserAndAccount() публичный Метод

When overridden in a derived class, creates a new user profile and a new membership account.
public CreateUserAndAccount ( string userName, string password, bool requireConfirmation, object>.IDictionary values ) : string
userName string The user name.
password string The password.
requireConfirmation bool (Optional) true to specify that the user account must be confirmed; otherwise, false. The default is false.
values object>.IDictionary (Optional) A dictionary that contains additional user attributes to store in the user profile. The default is null.
Результат string

DeleteAccount() публичный Метод

When overridden in a derived class, deletes the specified membership account.
public DeleteAccount ( string userName ) : bool
userName string The user name.
Результат bool

DeleteOAuthAccount() публичный Метод

When overridden in a derived class, deletes the OAuth or OpenID account with the specified provider name and provider user ID.
public DeleteOAuthAccount ( string provider, string providerUserId ) : void
provider string The name of the OAuth or OpenID provider.
providerUserId string The OAuth or OpenID provider user ID. This is not the user ID of the user account, but the user ID on the OAuth or Open ID provider.
Результат void

DeleteOAuthToken() публичный Метод

Deletes the OAuth token from the backing store from the database.
public DeleteOAuthToken ( string token ) : void
token string The token to be deleted.
Результат void

DeleteUser() публичный Метод

Removes a user from the membership data source.
public DeleteUser ( string userName, bool deleteAllRelatedData ) : bool
userName string Name of the user.
deleteAllRelatedData bool true to delete data related to the user from the database; false to leave data related to the user in the database.
Результат bool

FindUsersByEmail() публичный Метод

Gets a collection of membership users where the e-mail address contains the specified e-mail address to match.
public FindUsersByEmail ( string emailToMatch, int pageIndex, int pageSize, int &totalRecords ) : System.Web.Security.MembershipUserCollection
emailToMatch string The e-mail address to search for.
pageIndex int The index of the page of results to return. is zero-based.
pageSize int The size of the page of results to return.
totalRecords int The total number of matched users.
Результат System.Web.Security.MembershipUserCollection

FindUsersByName() публичный Метод

Gets a collection of membership users where the user name contains the specified user name to match.
public FindUsersByName ( string usernameToMatch, int pageIndex, int pageSize, int &totalRecords ) : System.Web.Security.MembershipUserCollection
usernameToMatch string The user name to search for.
pageIndex int The index of the page of results to return. is zero-based.
pageSize int The size of the page of results to return.
totalRecords int The total number of matched users.
Результат System.Web.Security.MembershipUserCollection

GeneratePasswordResetToken() публичный Метод

When overridden in a derived class, generates a password reset token that can be sent to a user in email.
Argument cannot be null or empty.;userName Unable to update simple membership database.
public GeneratePasswordResetToken ( string userName, int tokenExpirationInMinutesFromNow ) : string
userName string The user name.
tokenExpirationInMinutesFromNow int (Optional) The time, in minutes, until the password reset token expires. The default is 1440 (24 hours).
Результат string

GetAccountsForUser() публичный Метод

When overridden in a derived class, returns all OAuth membership accounts associated with the specified user name.
public GetAccountsForUser ( string userName ) : ICollection
userName string The user name.
Результат ICollection

GetAllUsers() публичный Метод

Gets a collection of all the users in the data source in pages of data.
public GetAllUsers ( int pageIndex, int pageSize, int &totalRecords ) : System.Web.Security.MembershipUserCollection
pageIndex int The index of the page of results to return. is zero-based.
pageSize int The size of the page of results to return.
totalRecords int The total number of matched users.
Результат System.Web.Security.MembershipUserCollection

GetCreateDate() публичный Метод

When overridden in a derived class, returns the date and time when the specified user account was created.
public GetCreateDate ( string userName ) : System.DateTime
userName string The user name of the account.
Результат System.DateTime

GetLastPasswordFailureDate() публичный Метод

When overridden in a derived class, returns the date and time when an incorrect password was most recently entered for the specified user account.
public GetLastPasswordFailureDate ( string userName ) : System.DateTime
userName string The user name of the account.
Результат System.DateTime

GetNumberOfUsersOnline() публичный Метод

Gets the number of users currently accessing the application.
public GetNumberOfUsersOnline ( ) : int
Результат int

GetOAuthTokenSecret() публичный Метод

Gets the O auth token secret.
public GetOAuthTokenSecret ( string token ) : string
token string The token.
Результат string

GetPassword() публичный Метод

Gets the password for the specified user name from the data source.
public GetPassword ( string username, string answer ) : string
username string The user to retrieve the password for.
answer string The password answer for the user.
Результат string

GetPasswordChangedDate() публичный Метод

When overridden in a derived class, returns the date and time when the password was most recently changed for the specified membership account.
public GetPasswordChangedDate ( string userName ) : System.DateTime
userName string The user name of the account.
Результат System.DateTime

GetPasswordFailuresSinceLastSuccess() публичный Метод

When overridden in a derived class, returns the number of times that the password for the specified user account was incorrectly entered since the most recent successful login or since the user account was created.
public GetPasswordFailuresSinceLastSuccess ( string userName ) : int
userName string The user name of the account.
Результат int

GetUser() публичный Метод

Gets user information from the data source based on the unique identifier for the membership user. Provides an option to update the last-activity date/time stamp for the user.
public GetUser ( object providerUserKey, bool userIsOnline ) : System.Web.Security.MembershipUser
providerUserKey object The unique identifier for the membership user to get information for.
userIsOnline bool true to update the last-activity date/time stamp for the user; false to return user information without updating the last-activity date/time stamp for the user.
Результат System.Web.Security.MembershipUser

GetUser() публичный Метод

Gets information from the data source for a user. Provides an option to update the last-activity date/time stamp for the user.
public GetUser ( string username, bool userIsOnline ) : System.Web.Security.MembershipUser
username string The name of the user to get information for.
userIsOnline bool true to update the last-activity date/time stamp for the user; false to return user information without updating the last-activity date/time stamp for the user.
Результат System.Web.Security.MembershipUser

GetUserId() защищенный Метод

Gets the user id.
protected GetUserId ( DapperContext db, string userTableName, string userNameColumn, string userIdColumn, string userName ) : int
db DapperContext The db.
userTableName string Name of the user table.
userNameColumn string The user name column.
userIdColumn string The user id column.
userName string Name of the user.
Результат int

GetUserId() публичный Метод

Gets the user id.
public GetUserId ( string userName ) : int
userName string Name of the user.
Результат int

GetUserIdFromOAuth() публичный Метод

When overridden in a derived class, returns the user ID for the specified OAuth or OpenID provider and provider user ID.
public GetUserIdFromOAuth ( string provider, string providerUserId ) : int
provider string The name of the OAuth or OpenID provider.
providerUserId string The OAuth or OpenID provider user ID. This is not the user ID of the user account, but the user ID on the OAuth or Open ID provider.
Результат int

GetUserIdFromPasswordResetToken() публичный Метод

When overridden in a derived class, returns an ID for a user based on a password reset token.
public GetUserIdFromPasswordResetToken ( string token ) : int
token string The password reset token.
Результат int

GetUserNameByEmail() публичный Метод

Gets the user name associated with the specified e-mail address.
public GetUserNameByEmail ( string email ) : string
email string The e-mail address to search for.
Результат string

GetUserNameFromId() публичный Метод

Returns the user name that is associated with the specified user ID.
public GetUserNameFromId ( int userId ) : string
userId int The user ID to get the name for.
Результат string

HasLocalAccount() публичный Метод

Determines whether there exists a local account (as opposed to OAuth account) with the specified userId.
public HasLocalAccount ( int userId ) : bool
userId int The user id to check for local account.
Результат bool

Initialize() публичный Метод

Initializes the provider.
config
public Initialize ( string name, NameValueCollection config ) : void
name string The friendly name of the provider.
config System.Collections.Specialized.NameValueCollection A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider.
Результат void

IsConfirmed() публичный Метод

When overridden in a derived class, returns a value that indicates whether the user account has been confirmed by the provider.
userName
public IsConfirmed ( string userName ) : bool
userName string The user name.
Результат bool

PhunSimpleMembershipProvider() публичный Метод

Initializes a new instance of the PhunSimpleMembershipProvider class.
public PhunSimpleMembershipProvider ( ) : System
Результат System

PhunSimpleMembershipProvider() публичный Метод

Initializes a new instance of the PhunSimpleMembershipProvider class.
public PhunSimpleMembershipProvider ( MembershipProvider previousProvider ) : System
previousProvider System.Web.Security.MembershipProvider The previous provider.
Результат System

ReplaceOAuthRequestTokenWithAccessToken() публичный Метод

Replaces the request token with access token and secret.
public ReplaceOAuthRequestTokenWithAccessToken ( string requestToken, string accessToken, string accessTokenSecret ) : void
requestToken string The request token.
accessToken string The access token.
accessTokenSecret string The access token secret.
Результат void

ResetPassword() публичный Метод

Resets a user's password to a new, automatically generated password.
public ResetPassword ( string username, string answer ) : string
username string The user to reset the password for.
answer string The password answer for the specified user.
Результат string

ResetPasswordWithToken() публичный Метод

When overridden in a derived class, resets a password after verifying that the specified password reset token is valid.
newPassword
public ResetPasswordWithToken ( string token, string newPassword ) : bool
token string A password reset token.
newPassword string The new password.
Результат bool

StoreOAuthRequestToken() публичный Метод

Stores the O auth request token.
public StoreOAuthRequestToken ( string requestToken, string requestTokenSecret ) : void
requestToken string The request token.
requestTokenSecret string The request token secret.
Результат void

UnlockUser() публичный Метод

Clears a lock so that the membership user can be validated.
public UnlockUser ( string userName ) : bool
userName string The membership user whose lock status you want to clear.
Результат bool

UpdateUser() публичный Метод

Updates information about a user in the data source.
public UpdateUser ( System.Web.Security.MembershipUser user ) : void
user System.Web.Security.MembershipUser A object that represents the user to update and the updated information for the user.
Результат void

ValidateUser() публичный Метод

Verifies that the specified user name and password exist in the data source.
/// username /// or /// password ///
public ValidateUser ( string username, string password ) : bool
username string The name of the user to validate.
password string The password for the specified user.
Результат bool

VerifyInitialized() защищенный Метод

Verifies the initialized.
Initialize must be called first.
protected VerifyInitialized ( ) : void
Результат void