public override void UpdateUser(System.Web.Security.MembershipUser member) { global::SoftFluent.Samples.GED.Security.User user = global::SoftFluent.Samples.GED.Security.User.LoadByUserName(member.UserName); if (user == null) { return; } user.Email = member.Email; user.LastLoginDate = member.LastLoginDate.ToUniversalTime(); user.LastActivityDate = member.LastActivityDate.ToUniversalTime(); user.Save(); }
public override bool UnlockUser(string username) { global::SoftFluent.Samples.GED.Security.User user = global::SoftFluent.Samples.GED.Security.User.LoadByUserName(username); if (user == null) { return(false); } SetAttempt(user, true); user.Save(); return(true); }
public override string ResetPassword(string username, string passwordAnswer) { if (!EnablePasswordReset) { throw new NotSupportedException(SoftFluent.Samples.GED.Resources.Manager.GetStringWithDefault("PasswordResetUnsupported", "Membership provider is not configured to support password resets.")); } global::SoftFluent.Samples.GED.Security.User user = global::SoftFluent.Samples.GED.Security.User.LoadByUserName(username); if (user == null) { throw new ProviderException(SoftFluent.Samples.GED.Resources.Manager.GetStringWithDefault("UserNotFound", "User '" + username + "' was not found.")); } if (user.IsLockedOut) { throw new MembershipPasswordException(SoftFluent.Samples.GED.Resources.Manager.GetStringWithDefault("UserLockedOut", "User '" + username + "' is locked out.")); } string password = Membership.GeneratePassword(MinRequiredPasswordLength, MinRequiredNonAlphanumericCharacters); user.Password = EncodePassword(password, user.PasswordSalt); ValidatePasswordEventArgs e = new ValidatePasswordEventArgs(username, user.Password, false); OnValidatingPassword(e); if (e.Cancel) { if (e.FailureInformation != null) { throw e.FailureInformation; } throw new ProviderException(SoftFluent.Samples.GED.Resources.Manager.GetStringWithDefault("PasswordInvalidCustom", "Password is invalid")); } user.Save(); return(password); }
public virtual global::SoftFluent.Samples.GED.Security.User ValidateAndGetUser(string username, string password, bool login) { if (username == null) { throw new ArgumentNullException("username"); } if (password == null) { throw new ArgumentNullException("password"); } global::SoftFluent.Samples.GED.Security.User user = global::SoftFluent.Samples.GED.Security.User.LoadByUserName(username); if (user == null) { return(null); } if (user.IsLockedOut) { return(null); } string encodedPassword = EncodePassword(password, user.PasswordSalt); if (encodedPassword != user.Password) { SetAttempt(user, false); user.Save(); return(null); } UpdateActivity(user, login); return(user); }
public override System.Web.Security.MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { global::SoftFluent.Samples.GED.Security.User user = new global::SoftFluent.Samples.GED.Security.User(); if (providerUserKey != null) { if (providerUserKey is System.Guid) { user.Id = (System.Guid)providerUserKey; } else { status = MembershipCreateStatus.InvalidProviderUserKey; return(null); } } email = ConvertUtilities.Nullify(email, true); if ((email != null) && (email.Length > 256)) { status = MembershipCreateStatus.InvalidEmail; return(null); } if ((email == null) && RequiresUniqueEmail) { status = MembershipCreateStatus.InvalidEmail; return(null); } user.Email = email; password = ConvertUtilities.Nullify(password, true); user.PasswordSalt = GenerateSalt(); string encodedPassword = EncodePassword(password, user.PasswordSalt); if ((password == null) || (password.Length > 256)) { status = MembershipCreateStatus.InvalidPassword; return(null); } user.Password = encodedPassword; username = ConvertUtilities.Nullify(username, true); if ((username == null) || (username.Length > 256)) { status = MembershipCreateStatus.InvalidUserName; return(null); } user.UserName = username; DateTime time = DateTime.UtcNow; time = new DateTime(time.Year, time.Month, time.Day, time.Hour, time.Minute, time.Second); user.IsLockedOut = false; user.LastLoginDate = time; user.LastActivityDate = time; user.LastPasswordChangeDate = time; user.LastLockoutDate = DateTime.MinValue; if (password.Length < MinRequiredPasswordLength) { status = MembershipCreateStatus.InvalidPassword; return(null); } int min = 0; for (int i = 0; i < password.Length; i++) { if (!char.IsLetterOrDigit(password, i)) { min++; } } if (min < MinRequiredNonAlphanumericCharacters) { status = MembershipCreateStatus.InvalidPassword; return(null); } if ((!string.IsNullOrEmpty(PasswordStrengthRegularExpression)) && (!Regex.IsMatch(password, PasswordStrengthRegularExpression))) { status = MembershipCreateStatus.InvalidPassword; return(null); } ValidatePasswordEventArgs e = new ValidatePasswordEventArgs(username, password, true); OnValidatingPassword(e); if (e.Cancel) { status = MembershipCreateStatus.InvalidPassword; return(null); } try { user.Save(); } catch (CodeFluent.Runtime.CodeFluentDuplicateException) { status = MembershipCreateStatus.DuplicateProviderUserKey; return(null); } status = MembershipCreateStatus.Success; return(MembershipUserFromUser(user)); }
public override bool ChangePassword(string username, string oldPassword, string newPassword) { if ((string.IsNullOrEmpty(username)) || (username.Length > 256)) { throw new ArgumentNullException("username"); } if ((string.IsNullOrEmpty(oldPassword)) || (oldPassword.Length > 256)) { throw new ArgumentNullException("oldPassword"); } if ((string.IsNullOrEmpty(newPassword)) || (newPassword.Length > 256)) { throw new ArgumentNullException("newPassword"); } if (newPassword.Length < MinRequiredPasswordLength) { throw new ArgumentException(SoftFluent.Samples.GED.Resources.Manager.GetStringWithDefault("PasswordTooShort", "Password is too short. Minimum length is {0}", new object[] { MinRequiredPasswordLength })); } int min = 0; for (int i = 0; i < newPassword.Length; i++) { if (!char.IsLetterOrDigit(newPassword, i)) { min++; } } if (min < MinRequiredNonAlphanumericCharacters) { throw new ArgumentException(SoftFluent.Samples.GED.Resources.Manager.GetStringWithDefault("PasswordTooAlpha", "Password needs more non alpha numeric characters. Minimum is {0}", new object[] { MinRequiredNonAlphanumericCharacters })); } if ((PasswordStrengthRegularExpression.Length > 0) && !Regex.IsMatch(newPassword, PasswordStrengthRegularExpression)) { throw new ArgumentException(SoftFluent.Samples.GED.Resources.Manager.GetStringWithDefault("PasswordInvalid", "Password does not match regular expression")); } global::SoftFluent.Samples.GED.Security.User user = global::SoftFluent.Samples.GED.Security.User.LoadByUserName(username); if (user == null) { return(false); } if (!CheckPassword(user, oldPassword)) { SetAttempt(user, false); user.Save(); return(false); } string encodedPassword = EncodePassword(newPassword, user.PasswordSalt); if (encodedPassword.Length > 256) { SetAttempt(user, false); user.Save(); throw new ArgumentException(SoftFluent.Samples.GED.Resources.Manager.GetStringWithDefault("PasswordTooLong", "Password is too long")); } ValidatePasswordEventArgs e = new ValidatePasswordEventArgs(username, encodedPassword, false); OnValidatingPassword(e); if (e.Cancel) { if (e.FailureInformation != null) { throw e.FailureInformation; } throw new ArgumentException(SoftFluent.Samples.GED.Resources.Manager.GetStringWithDefault("PasswordInvalidCustom", "Password is invalid")); } user.Password = encodedPassword; user.Save(); return(true); }
public override System.Web.Security.MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { global::SoftFluent.Samples.GED.Security.User user = new global::SoftFluent.Samples.GED.Security.User(); if (providerUserKey != null) { if (providerUserKey is System.Guid) { user.Id = (System.Guid)providerUserKey; } else { status = MembershipCreateStatus.InvalidProviderUserKey; return null; } } email = ConvertUtilities.Nullify(email, true); if ((email != null) && (email.Length > 256)) { status = MembershipCreateStatus.InvalidEmail; return null; } if ((email == null) && RequiresUniqueEmail) { status = MembershipCreateStatus.InvalidEmail; return null; } user.Email = email; password = ConvertUtilities.Nullify(password, true); user.PasswordSalt = GenerateSalt(); string encodedPassword = EncodePassword(password, user.PasswordSalt); if ((password == null) || (password.Length > 256)) { status = MembershipCreateStatus.InvalidPassword; return null; } user.Password = encodedPassword; username = ConvertUtilities.Nullify(username, true); if ((username == null) || (username.Length > 256)) { status = MembershipCreateStatus.InvalidUserName; return null; } user.UserName = username; DateTime time = DateTime.UtcNow; time = new DateTime(time.Year, time.Month, time.Day, time.Hour, time.Minute, time.Second); user.IsLockedOut = false; user.LastLoginDate = time; user.LastActivityDate = time; user.LastPasswordChangeDate = time; user.LastLockoutDate = DateTime.MinValue; if (password.Length < MinRequiredPasswordLength) { status = MembershipCreateStatus.InvalidPassword; return null; } int min = 0; for (int i = 0; i < password.Length; i++) { if (!char.IsLetterOrDigit(password, i)) { min++; } } if (min < MinRequiredNonAlphanumericCharacters) { status = MembershipCreateStatus.InvalidPassword; return null; } if ((!string.IsNullOrEmpty(PasswordStrengthRegularExpression)) && (!Regex.IsMatch(password, PasswordStrengthRegularExpression))) { status = MembershipCreateStatus.InvalidPassword; return null; } ValidatePasswordEventArgs e = new ValidatePasswordEventArgs(username, password, true); OnValidatingPassword(e); if (e.Cancel) { status = MembershipCreateStatus.InvalidPassword; return null; } try { user.Save(); } catch(CodeFluent.Runtime.CodeFluentDuplicateException) { status = MembershipCreateStatus.DuplicateProviderUserKey; return null; } status = MembershipCreateStatus.Success; return MembershipUserFromUser(user); }