C# Class 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!!!!
Inheritance: WebMatrix.WebData.ExtendedMembershipProvider
Datei anzeigen Open project: noogen/phuncms Class Usage Examples

Private Properties

Property Type Description
CheckPassword bool
ConnectToDatabase DapperContext
CreateOAuthTokenTableIfNeeded void
DeleteUserAndAccountInternal bool
GenerateToken string
GenerateToken string
GetHashedPassword string
GetPasswordFailureCount int
SetPassword bool
ValidateUserTable void
VerifyUserNameHasConfirmedAccount int

Public Methods

Method Description
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.

Protected Methods

Method Description
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.

Private Methods

Method Description
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.

Method Details

ChangePassword() public method

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.
return bool

ChangePasswordQuestionAndAnswer() public method

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.
return bool

ConfirmAccount() public method

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.
return bool

ConfirmAccount() public method

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.
return bool

CreateAccount() public method

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.
return string

CreateOrUpdateOAuthAccount() public method

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.
return void

CreateTablesIfNeeded() protected method

Creates the tables if needed.
protected CreateTablesIfNeeded ( ) : void
return void

CreateUser() public method

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.
return System.Web.Security.MembershipUser

CreateUserAndAccount() public method

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.
return string

DeleteAccount() public method

When overridden in a derived class, deletes the specified membership account.
public DeleteAccount ( string userName ) : bool
userName string The user name.
return bool

DeleteOAuthAccount() public method

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.
return void

DeleteOAuthToken() public method

Deletes the OAuth token from the backing store from the database.
public DeleteOAuthToken ( string token ) : void
token string The token to be deleted.
return void

DeleteUser() public method

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.
return bool

FindUsersByEmail() public method

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.
return System.Web.Security.MembershipUserCollection

FindUsersByName() public method

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.
return System.Web.Security.MembershipUserCollection

GeneratePasswordResetToken() public method

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).
return string

GetAccountsForUser() public method

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.
return ICollection

GetAllUsers() public method

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.
return System.Web.Security.MembershipUserCollection

GetCreateDate() public method

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.
return System.DateTime

GetLastPasswordFailureDate() public method

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.
return System.DateTime

GetNumberOfUsersOnline() public method

Gets the number of users currently accessing the application.
public GetNumberOfUsersOnline ( ) : int
return int

GetOAuthTokenSecret() public method

Gets the O auth token secret.
public GetOAuthTokenSecret ( string token ) : string
token string The token.
return string

GetPassword() public method

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.
return string

GetPasswordChangedDate() public method

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.
return System.DateTime

GetPasswordFailuresSinceLastSuccess() public method

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.
return int

GetUser() public method

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.
return System.Web.Security.MembershipUser

GetUser() public method

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.
return System.Web.Security.MembershipUser

GetUserId() protected method

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.
return int

GetUserId() public method

Gets the user id.
public GetUserId ( string userName ) : int
userName string Name of the user.
return int

GetUserIdFromOAuth() public method

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.
return int

GetUserIdFromPasswordResetToken() public method

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.
return int

GetUserNameByEmail() public method

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.
return string

GetUserNameFromId() public method

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.
return string

HasLocalAccount() public method

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.
return bool

Initialize() public method

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.
return void

IsConfirmed() public method

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.
return bool

PhunSimpleMembershipProvider() public method

Initializes a new instance of the PhunSimpleMembershipProvider class.
public PhunSimpleMembershipProvider ( ) : System
return System

PhunSimpleMembershipProvider() public method

Initializes a new instance of the PhunSimpleMembershipProvider class.
public PhunSimpleMembershipProvider ( MembershipProvider previousProvider ) : System
previousProvider System.Web.Security.MembershipProvider The previous provider.
return System

ReplaceOAuthRequestTokenWithAccessToken() public method

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.
return void

ResetPassword() public method

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.
return string

ResetPasswordWithToken() public method

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.
return bool

StoreOAuthRequestToken() public method

Stores the O auth request token.
public StoreOAuthRequestToken ( string requestToken, string requestTokenSecret ) : void
requestToken string The request token.
requestTokenSecret string The request token secret.
return void

UnlockUser() public method

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.
return bool

UpdateUser() public method

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.
return void

ValidateUser() public method

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.
return bool

VerifyInitialized() protected method

Verifies the initialized.
Initialize must be called first.
protected VerifyInitialized ( ) : void
return void