예제 #1
0
        public void ChangePassword_ExpiredResetPasswordRequest()
        {
            //Arrange
            var    mock        = new Mock <IDataAccess>();
            string resetCode   = "123Reset";
            string email       = "Email@123";
            string newPassword = "******";

            mock.Setup(D => D.Retrieve <PasswordRequest>()).Returns(new List <PasswordRequest>()
            {
                new PasswordRequest(resetCode, email)
                {
                    ExpirationDate = DateTime.Now.AddHours(-1)
                },
                new PasswordRequest(resetCode + "1", "WrongEMail"),
                new PasswordRequest(resetCode + "2", "AnotherWrongEmail")
            });
            mock.Setup(D => D.Retrieve <ApplicationUser>()).Returns(new List <ApplicationUser>()
            {
                new ApplicationUser(email, "Password", ApplicationUser.Roles.PARTICIPANT, mock.Object),
                new ApplicationUser("Wrong@Email", "Password", ApplicationUser.Roles.PARTICIPANT, mock.Object),
                new ApplicationUser("More@WrongEmail", "Password", ApplicationUser.Roles.PARTICIPANT, mock.Object),
            });
            var mockFestivalManager = new Mock <IFestivalManager>();
            AuthorizationManager authorizationManager = new AuthorizationManager(mock.Object, mockFestivalManager.Object, GetConfigurationMock());
            bool expected = false;

            //Act
            bool result = authorizationManager.ChangePassword(resetCode, email, newPassword);

            //Assert
            Assert.Equal(expected, result);
        }
예제 #2
0
        public void ChangePassword_CorrectlyChangesPassword()
        {
            //Arrange
            var    mock        = new Mock <IDataAccess>();
            string resetCode   = "123Reset";
            string email       = "Email@123";
            string newPassword = "******";

            mock.Setup(D => D.Retrieve <PasswordRequest>()).Returns(new List <PasswordRequest>()
            {
                new PasswordRequest(resetCode, email),
                new PasswordRequest(resetCode + "1", "WrongEMail"),
                new PasswordRequest(resetCode + "2", "AnotherWrongEmail")
            });
            var ApplicationsUsers = GenerateApplicationUsers(email);

            mock.Setup(D => D.Retrieve <ApplicationUser>()).Returns(ApplicationsUsers);
            var mockFestivalManager = new Mock <IFestivalManager>();
            AuthorizationManager authorizationManager = new AuthorizationManager(mock.Object, mockFestivalManager.Object, GetConfigurationMock());
            string expectedPassword = authorizationManager.Encrypt(newPassword);

            //Act
            authorizationManager.ChangePassword(resetCode, email, newPassword);
            string actualPassword = ApplicationsUsers[0].Password;

            //Assert
            Assert.Equal(expectedPassword, actualPassword);
        }
예제 #3
0
        protected void Confirm_Click(object sender, EventArgs e)
        {
            if (!Request.IsAuthenticated)
            {
                FormsAuthentication.RedirectToLoginPage();
                return;
            }

            Repository repository = null;

            if (Application["repository"] != null)
            {
                repository = (Repository)Application["repository"];
            }

            string  nickname = User.Identity.Name;
            var     id       = repository.GetAccountId(nickname);
            Account account  = repository.GetAccount(id);

            if (!AuthorizationManager.PasswordMatch(nickname, InputActualPassword.Text))
            {
                return;
            }

            string fName = string.IsNullOrEmpty(InputFName.Text)
                ? account.FirstName : InputFName.Text;
            string lName = string.IsNullOrEmpty(InputLName.Text)
                ? account.LastName : InputLName.Text;
            string info = string.IsNullOrEmpty(InputInformation.Text)
                ? account.Information : InputInformation.Text;
            string email = string.IsNullOrEmpty(InputEmail.Text)
                ? account.RegistrationInfo.Email : InputEmail.Text;
            DateTime?birthDate = string.IsNullOrEmpty(InputBirthDate.Text)
                ? account.BirthDate : DateTime.Parse(InputBirthDate.Text);

            if (!string.IsNullOrEmpty(InputPassword.Text) &&
                string.Equals(InputPassword.Text, InputPassword2.Text))
            {
                AuthorizationManager.ChangePassword(nickname, InputPassword.Text);
            }

            if (PhotoUpload.HasFile && PhotoUpload.FileName.EndsWith(".jpg"))
            {
                PhotoUpload.SaveAs(Server.MapPath("~/Photos/photo_" + id + ".jpg"));
            }

            account.ChangeInformation(fName, lName, info, email, birthDate);

            Application["repository"] = repository;

            Response.Redirect("Page.aspx?id=" + id);
        }
예제 #4
0
        public IActionResult OnPostResetPassword()
        {
            bool   succses;
            string SecretCode       = Request.Form["CodeEntered"];
            string UserEmail        = Request.Form["EmailEntered2"].ToString().ToLower();
            string Password1Entered = Request.Form["Password1Entered"];
            string Password2Entered = Request.Form["Password2Entered"];

            if (Password1Entered == Password2Entered)
            {
                succses = AuthorizationManager.ChangePassword(SecretCode, UserEmail, Password1Entered);
                if (succses == true)
                {
                    return(RedirectToPage("./Index", new { Alert = "Password Changed" }));
                }
                else
                {
                    return(RedirectToPage("./ResetPassword", new { Alert = "Wrong Input" }));
                }
            }
            return(RedirectToPage("./ResetPassword", new { Alert = "Password Different" }));
        }