예제 #1
0
        public static Membership ToModel(this Data.Entities.Membership membership)
        {
            var membershipModel = new Membership();

            if (membership == null)
            {
                return membershipModel;
            }

            membershipModel.MembershipId = membership.MembershipId;
            membershipModel.DateLastLogin = membership.DateLastLogin;
            membershipModel.DateLockedOut = membership.DateLockedOut;
            membershipModel.DateModified = membership.DateModified;
            membershipModel.FailedPasswordAnswerAttemptCount = membership.FailedPasswordAnswerAttemptCount;
            membershipModel.FailedPasswordAnswerAttemptWindowStart = membership.FailedPasswordAnswerAttemptWindowStart;
            membershipModel.FailedPasswordAttemptCount = membership.FailedPasswordAttemptCount;
            membershipModel.FailedPasswordAttemptWindowStart = membership.FailedPasswordAttemptWindowStart;
            membershipModel.IsLockedOut = membership.IsLockedOut;
            membershipModel.IsApproved = membership.IsApproved;
            membershipModel.Password = membership.Password;
            membershipModel.PasswordAnswer = membership.PasswordAnswer;
            membershipModel.PasswordFormatId = membership.PasswordFormatId;
            membershipModel.PasswordQuestion = membership.PasswordQuestion;
            membershipModel.PasswordSalt = membership.PasswordSalt;
            membershipModel.DateLastActivity = membership.DateLastActivity;
            membershipModel.UserId = membership.UserId;

            if (membership.User != null)
            {
                membershipModel.User = membership.User.ToModel();
            }

            return membershipModel;
        }
        private bool UpdatePasswordAndAnswer(string newPassword, Membership membership, string hashedSecurityAnswer)
        {
            string salt = string.Empty;

            if (this.convertToHash)
            {
                membership.PasswordAnswer = hashedSecurityAnswer;
                membership.PasswordFormatId = (int)InverGrovePasswordFormat.Hashed;
                salt = salt.GetRandomSalt();
            }
            else
            {
                if (membership.PasswordFormatId == (int)InverGrovePasswordFormat.Hashed)
                {
                    salt = membership.PasswordSalt;
                }
                else
                {
                    membership.PasswordFormatId = (int)InverGrovePasswordFormat.Clear;
                }
            }

            membership.PasswordSalt = salt;
            membership.Password = newPassword.FormatPasscode((InverGrovePasswordFormat)membership.PasswordFormatId, membership.PasswordSalt);

            return this.UpdateMembershipData(membership);
        }
        private void UpdateLastLoginData(Membership membership)
        {
            var user = this.userService.GetUser(membership.UserId);
            user.LastActivityDate = DateTime.Now;

            this.UpdateUserData((User)user);

            membership.DateLastActivity = DateTime.Now;
            membership.DateLastLogin = DateTime.Now;

            this.UpdateMembershipData(membership);
        }
 private bool UpdateMembershipData(Membership membership)
 {
     return this.membershipService.UpdateMembership(membership);
 }
        private string GetGeneratedPassword(Membership membership)
        {
            if (membership == null)
            {
                return string.Empty;
            }

            string newPassword = GeneratePassword(this.MinRequiredPasswordLength, this.MinRequiredNonAlphanumericCharacters);

            if (this.convertToHash)
            {
                string salt = string.Empty;
                membership.PasswordFormatId = (int)InverGrovePasswordFormat.Hashed;
                membership.PasswordSalt = salt.GetRandomSalt();
            }

            membership.Password = newPassword.FormatPasscode((InverGrovePasswordFormat)membership.PasswordFormatId, membership.PasswordSalt);

            this.UpdateMembershipData(membership);

            return newPassword;
        }