private int Membership_CreateUser(string applicationName, string userName, string password, string salt, string email, string passwordQuestion, string passwordAnswer, bool isApproved, out DateTime createDate, bool uniqueEmail, int passwordFormat, ref object providerUserKey)
 {
     createDate = DateTime.UtcNow;
       using (MembershipEntities membershipEntities = ModelHelper.CreateMembershipEntities(this.ConnectionString))
       {
     Guid applicationId = (QueryHelper.GetApplication(membershipEntities, applicationName) ?? ModelHelper.CreateApplication(membershipEntities, applicationName)).ApplicationId;
     Guid? nullable1 = (Guid?) providerUserKey;
     User user = QueryHelper.GetUser(membershipEntities, userName, applicationName);
     Guid? nullable2 = user == null ? new Guid?() : new Guid?(user.UserId);
     bool flag;
     if (!nullable2.HasValue)
     {
       if (!nullable1.HasValue)
       {
     nullable2 = new Guid?(Guid.NewGuid());
       }
       else
       {
     Guid userId = nullable1.Value;
     if (QueryHelper.GetUser(membershipEntities, userId, applicationName) != null)
       return 10;
     nullable2 = new Guid?(nullable1.Value);
       }
       ModelHelper.CreateUser(membershipEntities, nullable2.Value, userName, applicationId, false);
       flag = true;
     }
     else
     {
       flag = false;
       if (nullable1.HasValue)
       {
     Guid? nullable3 = nullable2;
     Guid guid = nullable1.Value;
     if ((!nullable3.HasValue ? 1 : (nullable3.GetValueOrDefault() != guid ? 1 : 0)) != 0)
       return 6;
       }
     }
     if (QueryHelper.GetMembership(membershipEntities, applicationName, nullable2.Value) != null)
       return 6;
     if (uniqueEmail && QueryHelper.GetUserNameFromEmail(membershipEntities, email, applicationName) != null)
       return 7;
     if (!flag)
       user.LastActivityDate = createDate;
     MembershipEntity entity = new MembershipEntity();
     entity.ApplicationId = applicationId;
     entity.CreateDate = createDate;
     entity.Email = email;
     entity.FailedPasswordAnswerAttemptCount = 0;
     entity.FailedPasswordAnswerAttemptWindowsStart = DefaultMembershipProvider.NullDate;
     entity.FailedPasswordAttemptCount = 0;
     entity.FailedPasswordAttemptWindowStart = DefaultMembershipProvider.NullDate;
     entity.IsApproved = isApproved;
     entity.IsLockedOut = false;
     entity.LastLockoutDate = DefaultMembershipProvider.NullDate;
     entity.LastLoginDate = createDate;
     entity.LastPasswordChangedDate = createDate;
     entity.Password = password;
     entity.PasswordAnswer = passwordAnswer;
     entity.PasswordFormat = passwordFormat;
     entity.PasswordQuestion = passwordQuestion;
     entity.PasswordSalt = salt;
     entity.UserId = nullable2.Value;
     providerUserKey = (object) nullable2.Value;
     membershipEntities.Memberships.AddObject(entity);
     membershipEntities.SaveChanges();
     return 0;
       }
 }
 private string GetEncodedPasswordAnswer(MembershipEntity member, string passwordAnswer)
 {
     if (passwordAnswer != null)
     {
         passwordAnswer = passwordAnswer.Trim();
     }
     if (string.IsNullOrEmpty(passwordAnswer))
     {
         return passwordAnswer;
     }
     return this.EncodePassword(passwordAnswer, member.PasswordFormat, member.PasswordSalt);
 }
 private int Membership_CreateUser(string applicationName, string userName, string password, string salt, string email, string passwordQuestion, string passwordAnswer, bool isApproved, out DateTime createDate, bool uniqueEmail, int passwordFormat, ref object providerUserKey)
 {
     createDate = DateTime.UtcNow;
     using (MembershipContext context = ModelHelper.CreateMembershipContext(this.ConnectionString))
     {
         bool flag;
         bool createIfNotExist = true;
         Guid applicationId = QueryHelper.GetApplication(context, this.ApplicationName, createIfNotExist).ApplicationId;
         Guid? nullable = (Guid?) providerUserKey;
         User user = QueryHelper.GetUser(context, userName, applicationName);
         Guid? nullable2 = (user == null) ? null : new Guid?(user.UserId);
         if (!nullable2.HasValue)
         {
             if (!nullable.HasValue)
             {
                 nullable2 = new Guid?(Guid.NewGuid());
             }
             else
             {
                 Guid userId = nullable.Value;
                 if (QueryHelper.GetUser(context, userId, applicationName) != null)
                 {
                     return 10;
                 }
                 nullable2 = new Guid?(nullable.Value);
             }
             ModelHelper.CreateUser(context, nullable2.Value, userName, applicationId, false);
             flag = true;
         }
         else
         {
             flag = false;
             if (nullable.HasValue && (nullable2 != nullable.Value))
             {
                 return 6;
             }
         }
         if (QueryHelper.GetMembership(context, applicationName, nullable2.Value) != null)
         {
             return 6;
         }
         if (uniqueEmail && (QueryHelper.GetUserNameFromEmail(context, email, applicationName) != null))
         {
             return 7;
         }
         if (!flag)
         {
             user.LastActivityDate = createDate;
         }
         MembershipEntity entity = new MembershipEntity {
             ApplicationId = applicationId,
             CreateDate = createDate,
             Email = email,
             FailedPasswordAnswerAttemptCount = 0,
             FailedPasswordAnswerAttemptWindowsStart = NullDate,
             FailedPasswordAttemptCount = 0,
             FailedPasswordAttemptWindowStart = NullDate,
             IsApproved = isApproved,
             IsLockedOut = false,
             LastLockoutDate = NullDate,
             LastLoginDate = createDate,
             LastPasswordChangedDate = createDate,
             Password = password,
             PasswordAnswer = passwordAnswer,
             PasswordFormat = passwordFormat,
             PasswordQuestion = passwordQuestion,
             PasswordSalt = salt,
             UserId = nullable2.Value
         };
         providerUserKey = nullable2.Value;
         context.Memberships.Add(entity);
         context.SaveChanges();
         return 0;
     }
 }
 private bool CheckPassword(MembershipEntity membership, User user, string password, bool updateLastActivityDate, bool failIfNotApproved)
 {
     DateTime utcNow = DateTime.UtcNow;
     if ((membership == null) || membership.IsLockedOut)
     {
         return false;
     }
     if (!membership.IsApproved && failIfNotApproved)
     {
         return false;
     }
     bool flag = string.Compare(this.EncodePassword(password, membership.PasswordFormat, membership.PasswordSalt), membership.Password, StringComparison.Ordinal) == 0;
     if (flag)
     {
         if ((membership.FailedPasswordAttemptCount > 0) || (membership.FailedPasswordAnswerAttemptCount > 0))
         {
             membership.FailedPasswordAnswerAttemptCount = 0;
             membership.FailedPasswordAnswerAttemptWindowsStart = NullDate;
             membership.FailedPasswordAttemptCount = 0;
             membership.FailedPasswordAttemptWindowStart = NullDate;
             membership.LastLockoutDate = NullDate;
         }
     }
     else
     {
         if (utcNow > membership.FailedPasswordAttemptWindowStart.AddMinutes((double) this.PasswordAttemptWindow))
         {
             membership.FailedPasswordAttemptCount = 1;
         }
         else
         {
             membership.FailedPasswordAttemptCount++;
         }
         membership.FailedPasswordAttemptWindowStart = utcNow;
         if (membership.FailedPasswordAttemptCount >= this.MaxInvalidPasswordAttempts)
         {
             membership.IsLockedOut = true;
             membership.LastLockoutDate = utcNow;
         }
     }
     if (updateLastActivityDate)
     {
         membership.LastLoginDate = utcNow;
         if (user != null)
         {
             user.LastActivityDate = utcNow;
         }
     }
     return flag;
 }