public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { Items.User u = Bridge.GetUser(username); if (u != null) { status = MembershipCreateStatus.DuplicateUserName; return(null); } if (string.IsNullOrEmpty(username)) { status = MembershipCreateStatus.InvalidUserName; return(null); } if (string.IsNullOrEmpty(password)) { status = MembershipCreateStatus.InvalidPassword; return(null); } status = MembershipCreateStatus.Success; u = Bridge.CreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, providerUserKey); MembershipUser m = u.GetMembershipUser(this.Name); return(m); }
public override string ResetPassword(string username, string answer) { if (!EnablePasswordReset) { throw new NotSupportedException("Password reset is not supported"); } N2.Security.Items.User u = Bridge.GetUser(username); if (u != null) { // JH /* original implementation does not provide service as expected for ResetPassword. * MSDN: Resets a user's password to a new, automatically generated password. * u.IsLockedOut = false; * Bridge.Save(u); * return u.Password; */ if (RequiresQuestionAndAnswer && !string.Equals(u.PasswordAnswer, answer)) { throw new MembershipPasswordException("Incorrect password answer"); } string newPassword = GenerateRandomPassword(); u.Password = ToStoredPassword(newPassword); u.IsLockedOut = false; Bridge.Save(u); return(newPassword); } return(null); }
public override string[] GetRolesForUser(string username) { Items.User u = Bridge.GetUser(username); if (u != null) { return(u.GetRoles()); } return(new string[0]); }
public override bool ValidateUser(string username, string password) { Items.User u = Bridge.GetUser(username); if (u != null && u.Password == password) { return(true); } return(false); }
public override string GetPassword(string username, string answer) { Items.User u = Bridge.GetUser(username); if (u != null && u.PasswordAnswer.Equals(answer, StringComparison.InvariantCultureIgnoreCase)) { return(u.Password); } return(null); }
public override bool DeleteUser(string username, bool deleteAllRelatedData) { Items.User u = Bridge.GetUser(username); if (u == null) { return(false); } Bridge.Delete(u); return(true); }
public override bool ValidateUser(string username, string password) { N2.Security.Items.User u = Bridge.GetUser(username); if (u != null && u.Password == ToStoredPassword(password) && u.IsLogin) // JH { u.LastLoginDate = N2.Utility.CurrentTime(); // JH Bridge.Save(u); return(true); } return(false); }
public override bool ChangePassword(string username, string oldPassword, string newPassword) { N2.Security.Items.User u = Bridge.GetUser(username); if (u == null || u.Password != ToStoredPassword(oldPassword)) // JH { return(false); } u.Password = ToStoredPassword(newPassword); // JH Bridge.Save(u); return(true); }
public override bool ChangePassword(string username, string oldPassword, string newPassword) { Items.User u = Bridge.GetUser(username); if (u == null || u.Password != oldPassword) { return(false); } u.Password = newPassword; Bridge.Save(u); return(true); }
public override bool UnlockUser(string userName) { N2.Security.Items.User u = Bridge.GetUser(userName); if (u == null) { return(false); } u.IsLockedOut = false; Bridge.Save(u); return(true); }
public override string ResetPassword(string username, string answer) { Items.User u = Bridge.GetUser(username); if (u != null) { u.IsLockedOut = false; Bridge.Save(u); return(u.Password); } return(null); }
public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer) { N2.Security.Items.User u = Bridge.GetUser(username); if (u == null || u.Password != ToStoredPassword(password)) // JH { return(false); } u.PasswordQuestion = newPasswordQuestion; u.PasswordAnswer = newPasswordAnswer; Bridge.Save(u); return(true); }
public override MembershipUser GetUser(string username, bool userIsOnline) { return(Cache.GetValue(username, (un) => { N2.Security.Items.User u = Bridge.GetUser(username); if (u != null) { return u.GetMembershipUser(this.Name); } return null; })); }
public override bool IsUserInRole(string username, string roleName) { Items.User u = Bridge.GetUser(username); foreach (string userRole in u.Roles) { if (userRole.Equals(roleName)) { return(true); } } return(false); }
public override MembershipUser GetUser(string username, bool userIsOnline) { Items.User u = Bridge.GetUser(username); if (u != null) { if (userIsOnline) { u.LastActivityDate = DateTime.Now; } return(u.GetMembershipUser(this.Name)); } return(null); }
public virtual bool DeleteUserExternalLoginInfo(Items.User user, string loginProvider, string providerKey) { if (user == null) { throw new ArgumentNullException("user"); } var loginInfoItem = FindUserExternalLoginInfo(user, loginProvider, providerKey); if (loginInfoItem == null) { return(false); } DeleteExternalLoginInfoItem(loginInfoItem); return(true); }
public override void AddUsersToRoles(string[] usernames, string[] roleNames) { foreach (string username in usernames) { Items.User u = Bridge.GetUser(username); foreach (string role in roleNames) { if (!u.Roles.Contains(role)) { u.Roles.Add(role); Bridge.Save(u); } } } }
public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames) { foreach (string username in usernames) { Items.User u = Bridge.GetUser(username); foreach (string role in roleNames) { if (u.Roles.Contains(role)) { u.Roles.Remove(role); Bridge.Save(u); } } } }
public virtual bool AddUserExternalLoginInfo(Items.User user, string loginProvider, string providerKey) { if (user == null) { throw new ArgumentNullException("user"); } if (FindUserExternalLoginInfo(user, loginProvider, providerKey) != null) { return(false); } var loginInfoItem = activator.CreateInstance <UserExternalLoginInfo>(user); loginInfoItem.LoginProvider = loginProvider; loginInfoItem.ProviderKey = providerKey; SaveExternalLoginInfoItem(loginInfoItem); return(true); }
public override string[] GetRolesForUser(string username) { return(Cache.GetValue(username, (un) => { Items.User u = Bridge.GetUser(username); if (u != null) { return new CachedRoles { Roles = u.GetRoles() ?? new string[0] } } ; return new CachedRoles { Roles = new string[0] }; }).Roles); }
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { N2.Security.Items.User u = Bridge.GetUser(username); if (u != null) { status = MembershipCreateStatus.DuplicateUserName; return(null); } if (string.IsNullOrEmpty(username)) { status = MembershipCreateStatus.InvalidUserName; return(null); } if (string.IsNullOrEmpty(password)) { status = MembershipCreateStatus.InvalidPassword; return(null); } if (requiresUniqueEmail) { if (!string.IsNullOrEmpty(GetUserNameByEmail(email))) { status = MembershipCreateStatus.DuplicateEmail; return(null); } } var args = new ValidatePasswordEventArgs(username, password, true); OnValidatingPassword(args); if (args.Cancel) { throw new MembershipCreateUserException("Create user cancelled", args.FailureInformation); } status = MembershipCreateStatus.Success; u = Bridge.CreateUser(username, ToStoredPassword(password), // JH email, passwordQuestion, passwordAnswer, isApproved, providerUserKey); Cache.Expire(); MembershipUser m = u.GetMembershipUser(this.Name); return(m); }
public override void UpdateUser(MembershipUser user) { if (user == null) { throw new ArgumentNullException("user"); } N2.Security.Items.User u = Bridge.GetUser(user.UserName); if (u != null) { u.UpdateFromMembershipUser(user); // JH: note that password remains unaffected Bridge.Save(u); } else { throw new N2Exception("User '" + user.UserName + "' not found."); } }
public override void UpdateUser(MembershipUser user) { if (user == null) { throw new ArgumentNullException("user"); } Items.User u = Bridge.GetUser(user.UserName); if (u != null) { u.UpdateFromMembershipUser(user); Bridge.Save(u); } else { throw new N2Exception("User '" + user.UserName + "' not found."); } }
public override string GetPassword(string username, string answer) { if (!EnablePasswordRetrieval) { throw new NotSupportedException("Password retrieval is not supported"); } N2.Security.Items.User u = Bridge.GetUser(username); if (u != null) { if (RequiresQuestionAndAnswer && !string.Equals(u.PasswordAnswer, answer, StringComparison.InvariantCultureIgnoreCase)) // JH { throw new MembershipPasswordException("Invalid password answer"); } // Note: may throw exception for hashed passwords! return(FromStoredPassword(u.Password)); // JH } return(null); }
/// <summary> Returns login info for specific user and given provider, null: not found </summary> public virtual UserExternalLoginInfo FindUserExternalLoginInfo(Items.User user, string loginProvider, string providerKey) { return(Repository.Find(UserExternalLoginInfo.QueryLoginInfoParameter(loginProvider, providerKey, user)) .OfType <UserExternalLoginInfo>() .FirstOrDefault()); }
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { if (string.IsNullOrEmpty(username)) { status = MembershipCreateStatus.InvalidUserName; return(null); } if (string.IsNullOrEmpty(password)) { status = MembershipCreateStatus.InvalidPassword; return(null); } N2.Security.Items.User u = Bridge.GetUser(username); if (u != null) { if (u.IsLogin) { status = MembershipCreateStatus.DuplicateUserName; return(null); } else { // The user object may be a profile which isn't yet a user u.IsLogin = true; } } //access the property, not the field, in case overriden by a subclass if (RequiresUniqueEmail) { if (!string.IsNullOrEmpty(GetUserNameByEmail(email))) { status = MembershipCreateStatus.DuplicateEmail; return(null); } } var args = new ValidatePasswordEventArgs(username, password, true); OnValidatingPassword(args); if (args.Cancel) { throw new MembershipCreateUserException("Create user cancelled", args.FailureInformation); } status = MembershipCreateStatus.Success; if (u == null) { u = Bridge.CreateUser(username, ToStoredPassword(password), email, passwordQuestion, passwordAnswer, isApproved, providerUserKey); } else { u.Password = ToStoredPassword(password); u.Email = email; u.PasswordQuestion = passwordQuestion; u.PasswordAnswer = passwordAnswer; u.IsApproved = isApproved; } Cache.Expire(); MembershipUser m = u.GetMembershipUser(this.Name); return(m); }
/// <summary> Returns all login info for specific user </summary> public virtual IEnumerable <UserExternalLoginInfo> FindUserExternalLoginInfos(Items.User user) { if (user == null) { throw new ArgumentNullException("user"); } return(user.GetChildren().OfType <UserExternalLoginInfo>()); }
public bool RemoveUserFromRole(User user, string role) { if (user == null) throw new ArgumentNullException("user"); if (string.IsNullOrWhiteSpace(role)) return false; if (!user.Roles.Contains(role)) return false; user.Roles.Remove(role); Save(user); return true; }
private static ProfileInfo CreateProfile(User u) { return new ProfileInfo(u.Name, false, u.LastActivityDate, u.Updated, u.Details.Count); }
public bool AddUserToRoles(User user, string[] roles) { if (user == null) throw new ArgumentNullException("user"); if ((roles == null) || (roles.Length == 0)) throw new ArgumentNullException("roles"); var userList = GetUserContainer(false); if (userList == null) throw new ArgumentNullException("userList"); foreach (string role in roles) { if (string.IsNullOrWhiteSpace(role) || !userList.HasRole(role)) throw new ArgumentOutOfRangeException(string.Format("Unknown role {0}.", role)); if (user.Roles.Contains(role)) continue; user.Roles.Add(role); } Save(user); return true; }