Exemplo n.º 1
0
        public override bool ChangePasswordQuestionAndAnswer(string password, string newPasswordQuestion,
            string newPasswordAnswer)
        {
            if (!ValidatePassword(password))
                return false;

            var repository = new SecurityRepository();
            var user = repository.GetUser(Id);
            if (user != null)
            {
                user.PasswordQuestion = newPasswordQuestion;
                user.PasswordAnswer = newPasswordAnswer;
                repository.SaveUser(user);
            }
            return true;
        }
        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(email))
            {
                status = MembershipCreateStatus.InvalidEmail;
                return null;
            }

            if (!string.IsNullOrEmpty(password) && password.Length < MinRequiredPasswordLength)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            var repository = new SecurityRepository();

            if (repository.TestUserByLogin(username))
            {
                status = MembershipCreateStatus.DuplicateUserName;
                return null;
            }

            if (repository.TestUserByEmail(email))
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }

            var salt = SaltGenerator.GenerateSalt();

            var account = new User
            {
                Login = username,
                EMail = email,
                Salt = salt,
                FirstName = username,
                LastName = username,
                PasswordQuestion = passwordQuestion,
                PasswordAnswer = passwordAnswer
            };

            repository.SaveUser(account);

            var user = (AccountMembershipUser)GetUser(username, false);
            if (user != null)
            {
                user.SavePassword(password);
                status = MembershipCreateStatus.Success;
            }
            else
                status = MembershipCreateStatus.ProviderError;
            return user;
        }
Exemplo n.º 3
0
        public bool ChangeNameAndEMail(string password, string email, string firstName, string secondName, string lastName)
        {
            if (!ValidatePassword(password))
                return false;

            var repository = new SecurityRepository();
            var user = repository.GetUser(Id);
            if (user != null)
            {
                user.EMail = email;
                user.FirstName = firstName;
                user.SecondName = secondName;
                user.LastName = lastName;
                repository.SaveUser(user);
            }
            return true;
        }