Beispiel #1
0
 private void OnResetUserPassword(object obj)
 {
     usersToReset = obj as Users;
     OnConfirm(usersToReset.UserName);
 }
Beispiel #2
0
        // MembershipProvider.CreateUser
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, password, true);

            OnValidatingPassword(args);

            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            if (RequiresUniqueEmail && GetUserNameByEmail(email) != "")
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }

            MembershipUser u = GetUser(username, false);

            if (u == null)
            {
                DateTime createDate = DateTime.Now;
                int passwordFormat;
                switch (pPasswordFormat)
                {
                    case MembershipPasswordFormat.Clear:
                        passwordFormat = 0;
                        break;
                    case MembershipPasswordFormat.Encrypted:
                        passwordFormat = 2;
                        break;
                    case MembershipPasswordFormat.Hashed:
                        passwordFormat = 1;
                        break;
                    default:
                        passwordFormat = 0;
                        break;
                }

                using (var db = new SecurityEntities())
                {
                    var app = db.Applications.SingleOrDefault(a => a.ApplicationName == pApplicationName);

                    var user = new Users
                    {
                        UserName = username,
                        LoweredUserName = username.ToLower(),
                        Password = EncodePassword(password),
                        Email = email,
                        PasswordFormat = passwordFormat,
                        PasswordQuestion = passwordQuestion,
                        PasswordAnswer = EncodePassword(passwordAnswer),
                        IsApproved = isApproved,
                        CreateDate = createDate,
                        IsLockedOut = false,
                        LastLockoutDate = createDate,
                        FailedPasswordAttemptCount = 0,
                        FailedPasswordAttemptWindowStart = createDate,
                        FailedPasswordAnswerAttemptCount = 0,
                        FailedPasswordAnswerAttemptWindowStart = createDate,
                        LastActivityDate = System.DateTime.Now,
                        LastLoginDate = System.DateTime.Now,
                        LastPasswordChangedDate = System.DateTime.Now,
                        ApplicationId = app.ApplicationId
                    };
                    db.Users.Add(user);
                    status = MembershipCreateStatus.Success;
                    if (db.SaveChanges() > 0)
                        status = MembershipCreateStatus.Success;
                    else
                        status = MembershipCreateStatus.UserRejected;

                }

                return GetUser(username, false);
            }
            else
            {
                status = MembershipCreateStatus.DuplicateUserName;
            }

            return null;
        }
Beispiel #3
0
 private void OnAdd(object obj)
 {
     Users u = new Users();
     u.UserId = this._service.EntityContainer.GetEntitySet<Users>().Count == 0 ? 1 :
      this._service.EntityContainer.GetEntitySet<Users>().Max(p => p.UserId) + 1;
     u.Password = defaultPassword;
     u.IsAnonymous = false;
     u.IsApproved = true;
     u.IsLockedOut = true;
     u.CreateDate = DateTime.Now.Date;
     this._service.EntityContainer.GetEntitySet<Users>().Add(u);
     this.radUsersCollection.Items.MoveCurrentToLast();
     this.radUsersCollection.ScrollIntoView(this.SelectedUser);
     this.RaisePropertyChanged(() => this.UsersCollection);
     RefreshButtonState();
 }