/// <summary> /// Resets the password. /// </summary> /// <param name="passwordResetToken">The password reset token.</param> /// <param name="newPassword">The new password.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> /// <exception cref="System.InvalidOperationException"> /// The <seealso cref="Initialized"/> method was not called.-or- /// The <seealso cref="InitializeDatabaseConnection(string)"/> method was not called.-or- /// The <seealso cref="MySqlSimpleMembershipProvider"/> membership provider is not registered in the configuration of your site. /// For more information, contact your site's system administrator. /// </exception> public static bool ResetPassword(string passwordResetToken, string newPassword) { MySqlSimpleMembershipProvider provider = VerifyProvider(); Debug.Assert(provider != null); // VerifyProvider checks this return(provider.ResetPasswordWithToken(passwordResetToken, newPassword)); }
/// <summary> /// Returns the date and time when an incorrect password was most recently entered for the specified account. /// </summary> /// <param name="userName">The user name of the membership account.</param> /// <returns>The date and time when an incorrect password was most recently entered for this account, or <see cref="System.DateTime.MinValue"/> if an incorrect password has not been entered for this account.</returns> /// <exception cref="System.InvalidOperationException"> /// The <seealso cref="Initialized"/> method was not called.-or- /// The <seealso cref="InitializeDatabaseConnection(string)"/> method was not called.-or- /// The <seealso cref="MySqlSimpleMembershipProvider"/> membership provider is not registered in the configuration of your site. /// For more information, contact your site's system administrator. /// </exception> public static DateTime GetLastPasswordFailureDate(string userName) { MySqlSimpleMembershipProvider provider = VerifyProvider(); Debug.Assert(provider != null); // VerifyProvider checks this return(provider.GetLastPasswordFailureDate(userName)); }
/// <summary> /// Returns the number of times that the password for the specified account was incorrectly entered since the last successful login or since the membership account was created. /// </summary> /// <param name="userName">The user name of the account.</param> /// <returns>The count of failed password attempts for the specified account.</returns> /// <exception cref="System.InvalidOperationException"> /// The <seealso cref="Initialized"/> method was not called.-or- /// The <seealso cref="InitializeDatabaseConnection(string)"/> method was not called.-or- /// The <seealso cref="MySqlSimpleMembershipProvider"/> membership provider is not registered in the configuration of your site. /// For more information, contact your site's system administrator. /// </exception> public static int GetPasswordFailuresSinceLastSuccess(string userName) { MySqlSimpleMembershipProvider provider = VerifyProvider(); Debug.Assert(provider != null); // VerifyProvider checks this return(provider.GetPasswordFailuresSinceLastSuccess(userName)); }
/// <summary> /// Returns a value that indicates whether the specified membership account is temporarily locked because of too many failed password attempts in the specified time span. /// </summary> /// <param name="userName">The user name of the membership account.</param> /// <param name="allowedPasswordAttempts">The number of password attempts the user is permitted before the membership account is locked.</param> /// <param name="interval">The number of seconds to lock out a user account after the number of password attempts exceeds the value in the allowedPasswordAttempts parameter.</param> /// <returns><c>true</c> if the membership account is locked; otherwise, <c>false</c>.</returns> /// <exception cref="System.InvalidOperationException"> /// The <seealso cref="Initialized"/> method was not called.-or- /// The <seealso cref="InitializeDatabaseConnection(string)"/> method was not called.-or- /// The <seealso cref="MySqlSimpleMembershipProvider"/> membership provider is not registered in the configuration of your site. /// For more information, contact your site's system administrator. /// </exception> public static bool IsAccountLockedOut(string userName, int allowedPasswordAttempts, TimeSpan interval) { MySqlSimpleMembershipProvider provider = VerifyProvider(); Debug.Assert(provider != null); // VerifyProvider checks this return(IsAccountLockedOutInternal(provider, userName, allowedPasswordAttempts, interval)); }
/// <summary> /// Returns a value that indicates whether the user has been confirmed. /// </summary> /// <param name="userName">The user name.</param> /// <returns><c>true</c> if the user is confirmed; otherwise, <c>false</c>.</returns> public static bool IsConfirmed(string userName) { MySqlSimpleMembershipProvider provider = VerifyProvider(); Debug.Assert(provider != null); // VerifyProvider checks this return(provider.IsConfirmed(userName)); }
/// <summary> /// Returns a user ID from a password reset token. /// </summary> /// <param name="token">The password reset token.</param> /// <returns>The user ID.</returns> /// <exception cref="System.InvalidOperationException"> /// The <seealso cref="Initialized"/> method was not called.-or- /// The <seealso cref="InitializeDatabaseConnection(string)"/> method was not called.-or- /// The <seealso cref="MySqlSimpleMembershipProvider"/> membership provider is not registered in the configuration of your site. /// For more information, contact your site's system administrator. /// </exception> public static int GetUserIdFromPasswordResetToken(string token) { MySqlSimpleMembershipProvider provider = VerifyProvider(); Debug.Assert(provider != null); // VerifyProvider checks this return(provider.GetUserIdFromPasswordResetToken(token)); }
public static string GeneratePasswordResetToken(string userName, int tokenExpirationInMinutesFromNow = 1440) { MySqlSimpleMembershipProvider provider = VerifyProvider(); Debug.Assert(provider != null); // VerifyProvider checks this return(provider.GeneratePasswordResetToken(userName, tokenExpirationInMinutesFromNow)); }
private static MySqlSimpleMembershipProvider CreateDefaultExtendedMembershipProvider(string name, MembershipProvider currentDefault) { var membership = new MySqlSimpleMembershipProvider(currentDefault); var config = new NameValueCollection(); membership.Initialize(name, config); return(membership); }
internal static void InitializeMembershipProvider(MySqlSimpleMembershipProvider extendedMembership, DatabaseConnectionInfo connect) { if (extendedMembership.InitializeCalled) { throw new InvalidOperationException(Resources.Security.Security_InitializeAlreadyCalled); } extendedMembership.ConnectionInfo = connect; // We want to validate the user table if we aren't creating them extendedMembership.ValidateTable(); extendedMembership.InitializeCalled = true; }
private List <int> GetUserIdsFromNames(MySqlMembershipContext db, string[] usernames) { var userIds = new List <int>(usernames.Length); foreach (var username in usernames) { var id = MySqlSimpleMembershipProvider.GetUserId(db, username); if (id == -1) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Security.Security_NoUserFound, username)); } userIds.Add(id); } return(userIds); }
public SimpleMembership() { _simpleProvider = new MySqlSimpleMembershipProvider(); _simpleRoleProvider = new MySqlSimpleRoleProvider(); var _config = new NameValueCollection(); _config.Add("connectionStringName", "LocalMySqlServer"); _config.Add("userTableName", "UserProfile"); _config.Add("userIdColumn", "UserId"); _config.Add("userNameColumn", "UserName"); _simpleProvider.Initialize("Test", _config); _simpleRoleProvider.Initialize("TestRoleProvider", _config); MySqlWebSecurity.InitializeDatabaseConnection(ConnectionString, "MySqlSimpleMembership", _userTable, _userIdColumn, _userNameColumn, true, true); }
/// <summary> /// Gets a list of the roles that a specified user is in for the configured applicationName. /// </summary> /// <remarks>Inherited from RoleProvider ==> Forwarded to previous provider if this provider hasn't been initialized</remarks> /// <param name="username">The user to return a list of roles for.</param> /// <returns>A string array containing the names of all the roles that the specified user is in for the configured applicationName.</returns> /// <exception cref="System.InvalidOperationException"></exception> public override string[] GetRolesForUser(string username) { if (!InitializeCalled) { return(PreviousProvider.GetRolesForUser(username)); } using (var db = NewMySqlMembershipContext) { int userId = MySqlSimpleMembershipProvider.GetUserId(db, username); if (userId == -1) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Security.Security_NoUserFound, username)); } var roles = db.UsersInRoles.Where(x => x.UserId == userId) .Select(x => x.Role.RoleName) .ToArray(); return(roles); } }
internal static bool IsAccountLockedOutInternal(MySqlSimpleMembershipProvider provider, string userName, int allowedPasswordAttempts, TimeSpan interval) { return(provider.GetUser(userName, false) != null && provider.GetPasswordFailuresSinceLastSuccess(userName) > allowedPasswordAttempts && provider.GetLastPasswordFailureDate(userName).Add(interval) > DateTime.Now); }