Class MySqlWebSecurity
Provides security features for web projects implementing a MySql database.
Inheritance
Namespace: MySql.Web.Security
Assembly: MySql.Web.dll
Version: 9.1.0
Syntax
public static class MySqlWebSecurity
Fields
EnableSimpleMembershipKey
Name of the key required to enable simple membership.
Declaration
public static readonly string EnableSimpleMembershipKey
Field Value
Type | Description |
---|---|
System.String |
Properties
CurrentUserId
Gets the current user id.
Declaration
public static int CurrentUserId { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
CurrentUserName
Gets the current user name.
Declaration
public static string CurrentUserName { get; }
Property Value
Type | Description |
---|---|
System.String |
HasUserId
Gets a flag indicating if there is an associated user id.
Declaration
public static bool HasUserId { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Initialized
Gets the initialized status.
Declaration
public static bool Initialized { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsAuthenticated
Gets a flag indicating if the user is authenticated.
Declaration
public static bool IsAuthenticated { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
ChangePassword(String, String, String)
Changes the password for the user provided.
Declaration
public static bool ChangePassword(string userName, string oldPassword, string newPassword)
Parameters
Type | Name | Description |
---|---|---|
System.String | userName | The user name. |
System.String | oldPassword | The current pasword. |
System.String | newPassword | The new Password. |
Returns
Type | Description |
---|---|
System.Boolean |
ConfirmAccount(String)
Confirms user by confirmation token.
Declaration
public static bool ConfirmAccount(string confirmationToken)
Parameters
Type | Name | Description |
---|---|---|
System.String | confirmationToken | The confirmation token. |
Returns
Type | Description |
---|---|
System.Boolean |
|
ConfirmAccount(String, String)
Confirms user by confirmation token and user name.
Declaration
public static bool ConfirmAccount(string userName, string confirmationToken)
Parameters
Type | Name | Description |
---|---|---|
System.String | userName | The user name. |
System.String | confirmationToken | The confirmation token. |
Returns
Type | Description |
---|---|
System.Boolean |
|
CreateAccount(String, String, Boolean)
Creates a user account.
Declaration
public static string CreateAccount(string userName, string password, bool requireConfirmationToken = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | userName | The user name. |
System.String | password | The user password. |
System.Boolean | requireConfirmationToken | Flag to indicate if a confirmation token is required. |
Returns
Type | Description |
---|---|
System.String | A confirmation token if required. |
CreateUserAndAccount(String, String, Object, Boolean)
Creates user and account.
Declaration
public static string CreateUserAndAccount(string userName, string password, object additionalUserAttributes = null, bool requireConfirmationToken = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | userName | The user name. |
System.String | password | The user password. |
System.Object | additionalUserAttributes | Additional data for user table. |
System.Boolean | requireConfirmationToken | Flag to indicate if a confirmation token is required. |
Returns
Type | Description |
---|---|
System.String | A confirmation token if required. |
GeneratePasswordResetToken(String, Int32)
Generates password reset token for a confirmed user.
Declaration
public static string GeneratePasswordResetToken(string userName, int tokenExpirationInMinutesFromNow = 1440)
Parameters
Type | Name | Description |
---|---|---|
System.String | userName | The user name. |
System.Int32 | tokenExpirationInMinutesFromNow | The time that the token will be valid. |
Returns
Type | Description |
---|---|
System.String | A generated token or |
GetCreateDate(String)
Gets the date when the specified user was created.
Declaration
public static DateTime GetCreateDate(string userName)
Parameters
Type | Name | Description |
---|---|---|
System.String | userName | The user name. |
Returns
Type | Description |
---|---|
System.DateTime | Date created or minimum date value if the user was not found. |
GetLastPasswordFailureDate(String)
Gets the last date when password fails.
Declaration
public static DateTime GetLastPasswordFailureDate(string userName)
Parameters
Type | Name | Description |
---|---|---|
System.String | userName | The user name. |
Returns
Type | Description |
---|---|
System.DateTime | Last failure date or minimum date value if the user was not found. |
GetPasswordChangedDate(String)
Gets the date when password was changed.
Declaration
public static DateTime GetPasswordChangedDate(string userName)
Parameters
Type | Name | Description |
---|---|---|
System.String | userName | The user name. |
Returns
Type | Description |
---|---|
System.DateTime | Last password changed date or minimum date value if the user was not found. |
GetPasswordFailuresSinceLastSuccess(String)
Gets the password failures since last success.
Declaration
public static int GetPasswordFailuresSinceLastSuccess(string userName)
Parameters
Type | Name | Description |
---|---|---|
System.String | userName | The user name. |
Returns
Type | Description |
---|---|
System.Int32 | The number of failures since last success. |
GetUserId(String)
Gets the user id.
Declaration
public static int GetUserId(string userName)
Parameters
Type | Name | Description |
---|---|---|
System.String | userName | The user name. |
Returns
Type | Description |
---|---|
System.Int32 | The user id. -1 if the user doesn't exists |
GetUserIdFromPasswordResetToken(String)
Gets the user id from the password reset token.
Declaration
public static int GetUserIdFromPasswordResetToken(string resetToken)
Parameters
Type | Name | Description |
---|---|---|
System.String | resetToken | The reset token. |
Returns
Type | Description |
---|---|
System.Int32 | The user id. 0 if the user doesn't exists. |
InitializeDatabaseConnection(String, String, String, String, Boolean, Boolean)
Initializes the simple membership provider with the values given.
Declaration
public static void InitializeDatabaseConnection(string connectionStringName, string userTableName, string userIdColumn, string userNameColumn, bool createTables, bool checkIfInitialized = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | connectionStringName | The connection string name defined in the config file. |
System.String | userTableName | The table name defined to create new users. |
System.String | userIdColumn | The column name defined to store the user ids. |
System.String | userNameColumn | The column name defined to store the user name. |
System.Boolean | createTables | Flag indicating if the tables should be created. |
System.Boolean | checkIfInitialized | Flag indicating to check if the database has been initialized. |
InitializeDatabaseConnection(String, String, String, String, String, Boolean, Boolean)
Initializes the simple membership provider with the values given.
Declaration
public static void InitializeDatabaseConnection(string connectionString, string providerName, string userTableName, string userIdColumn, string userNameColumn, bool createTables, bool checkIfInitialized = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | connectionString | The connection string. |
System.String | providerName | The name of the provider. |
System.String | userTableName | The table name defined to create new users. |
System.String | userIdColumn | The column name defined to store the user ids. |
System.String | userNameColumn | The column name defined to store the user name. |
System.Boolean | createTables | Flag indicating if the tables should be created. |
System.Boolean | checkIfInitialized | Flag indicating to check if the database has been initialized. |
IsAccountLockedOut(String, Int32, Int32)
Determines if the account is locked out.
Declaration
public static bool IsAccountLockedOut(string userName, int allowedPasswordAttempts, int intervalInSeconds)
Parameters
Type | Name | Description |
---|---|---|
System.String | userName | The name of the user. |
System.Int32 | allowedPasswordAttempts | The number of allowed password attempts. |
System.Int32 | intervalInSeconds |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsAccountLockedOut(String, Int32, TimeSpan)
Determines if the account is locked out.
Declaration
public static bool IsAccountLockedOut(string userName, int allowedPasswordAttempts, TimeSpan interval)
Parameters
Type | Name | Description |
---|---|---|
System.String | userName | The name of the user. |
System.Int32 | allowedPasswordAttempts | The number of allowed password attempts. |
System.TimeSpan | interval |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsConfirmed(String)
Determines if the user has been confirmed.
Declaration
public static bool IsConfirmed(string userName)
Parameters
Type | Name | Description |
---|---|---|
System.String | userName | The user name. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsCurrentUser(String)
Determines if the CurrentUserName is the same as the provided user name.
Declaration
public static bool IsCurrentUser(string userName)
Parameters
Type | Name | Description |
---|---|---|
System.String | userName | The user name. |
Returns
Type | Description |
---|---|
System.Boolean |
|
IsUseLoggedOn(Int32)
Determines if the CurrentUserId matches the provided user id.
Declaration
public static bool IsUseLoggedOn(int userId)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | userId | The user id to match. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Login(String, String, Boolean)
Performs a login for the specified user.
Declaration
public static bool Login(string userName, string password, bool createPersistentCookie = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | userName | The user name. |
System.String | password | The user password. |
System.Boolean | createPersistentCookie | Flag to indicate if a persistent cookie should be created. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Logout()
Performs a logout for the current item.
Declaration
public static void Logout()
RequireAuthenticatedUser()
Evalutes if the user is authenticated.
Declaration
public static void RequireAuthenticatedUser()
RequireRoles(String[])
Evaluates if the user belongs to the specified roles.
Declaration
public static void RequireRoles(params string[] roles)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | roles |
RequiresUser(Int32)
Evaluates if the user is logged on.
Declaration
public static void RequiresUser(int userId)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | userId |
RequiresUser(String)
Evaluates if the provided user name matches the CurrentUserName.
Declaration
public static void RequiresUser(string userName)
Parameters
Type | Name | Description |
---|---|---|
System.String | userName |
ResetPassword(String, String)
Resets the password identified by the provided password reset token.
Declaration
public static bool ResetPassword(string passwordResetToken, string newPassword)
Parameters
Type | Name | Description |
---|---|---|
System.String | passwordResetToken | The password reset token. |
System.String | newPassword | The new password. |
Returns
Type | Description |
---|---|
System.Boolean |
|
UserExists(String)
Determines if the user exists.
Declaration
public static bool UserExists(string username)
Parameters
Type | Name | Description |
---|---|---|
System.String | username | The user name. |
Returns
Type | Description |
---|---|
System.Boolean |
|