public void HashingExpectTrue()
 {
     try
     {
         PasswordController passwordController = new PasswordController();
         string             pass = "******";
         string             salt =
             "ThN0qWHV8YV4nOI/kGwjNWRpw16kBt9enVuJaDQFFCRBxQNBFE" +
             "gu6vhHMb/9++njP32Z5fkrYC0K/cre9KKbgw==";
         string expectedOutput =
             "NPU+/EqR5h0Cs8SnFsJREoAIsmezp/8m4M3NPhLMY/GHz+SPBA0dk" +
             "7+VmZHlRAUMZzsYJWm1ZvZtr7XEaTwzRr/M5sKPrtvtSQrWKEEprczoC" +
             "oPTxPbq20OzXzLUgZ5CPVekeC617vYfvsc57vv9Ekj7hmpoLd05EJ9UHItwU" +
             "zwhuXLlMFoBK8/8WjKXZ09Hm1h8Sh+LUBXUqyEd4/zswOg2QQDcMjg8YiIQumQfk" +
             "3mZoVz3fFYv8uBHsKE2M0VzH7F7fyR70yP1Oq0VxIXF/qmJbVYn7yAbuNsaQDXRoXwa" +
             "2LjM/HQKjlAQhqTAzwephHD+x3/FOKAvpJMqKZNcug==";
         byte[] saltByte   = Encoding.UTF8.GetBytes(salt);
         string hashOutput = passwordController.GenerateHashedPassword(pass, saltByte);
         Debug.WriteLine(hashOutput);
         Assert.IsTrue(expectedOutput.Equals(hashOutput));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
Example #2
0
 public async Task VerifyLoginWithWrongPasswordAndWrongName()
 {
     try
     {
         PasswordController passwordController = new PasswordController();
         Assert.IsFalse(await passwordController.VerifyLogin("wrong", "Wrong"));
     }
     catch (EmptyInputException exc)
     {
         Console.WriteLine(exc.ReturnMessage);
         Assert.Fail();
     }
     catch (UserOrPasswordException exc)
     {
         Console.WriteLine(exc.ReturnMessage);
         Assert.IsTrue(true);
     }
     catch (FaultException <UserOrPasswordException> exc)
     {
         Console.WriteLine(exc.Message);
         Assert.Fail();
     }
     catch (FaultException <UserNotFoundException> exc)
     {
         Console.WriteLine(exc.Message);
         Assert.Fail();
     }
     catch (Exception exc)
     {
         Console.WriteLine(exc.Message);
         Assert.Fail();
     }
 }
Example #3
0
 public async Task VerifyLoginWithCorrectNameAndCorrectPassword()
 {
     try
     {
         PasswordController passwordController = new PasswordController();
         Assert.IsTrue(await passwordController.VerifyLogin("Aksel", "1234"));
     }
     catch (EmptyInputException exc)
     {
         Console.WriteLine(exc.ReturnMessage);
         Assert.Fail();
     }
     catch (UserOrPasswordException exc)
     {
         Console.WriteLine(exc.ReturnMessage);
         Assert.Fail();
     }
     catch (FaultException <UserOrPasswordException> exc)
     {
         Console.WriteLine(exc.Message);
         Assert.Fail();
     }
     catch (FaultException <UserNotFoundException> exc)
     {
         Console.WriteLine(exc.Message);
         Assert.Fail();
     }
     catch (Exception exc)
     {
         Console.WriteLine(exc.Message);
         Assert.Fail();
     }
 }
Example #4
0
 public frmMain(User user)
 {
     InitializeComponent();
     _user = user;
     _passwordController = new PasswordController();
     _noteController     = new NoteController();
 }
    private void Awake()
    {
        messageController          = messageUI.GetComponent <MessageController>();
        actionNavigationController = actionNavigator.GetComponent <ActionNavigationController>();
        padLockUIController        = padLockUI.GetComponent <PadLockUIController>();
        choiceUIController         = choiceUI.GetComponent <ChoiceUIController>();
        passwordController         = passwordUI.GetComponent <PasswordController>();
        riddleUIController         = riddleUI.GetComponent <RiddleUIController>();
        countDownUIController      = countDownUI.GetComponent <CountDownUIController>();
        eightPuzzle       = eightPuzzleObj.GetComponent <EightPuzzle>();
        enemyEnterProcess = GetComponent <EnemyEnterRoomProcess>();
        edit = GetComponent <Edit>();

        currentHasItemText = currentHasItemTextObj.GetComponent <Text>();

        if (eightPuzzleUI.activeSelf)
        {
            eightPuzzleUI.SetActive(false);
        }
        if (editUI)
        {
            editUI.SetActive(false);
        }

        roomCMonitor        = roomCMonitorObj.GetComponent <AirConMonitor>();
        entranceRoomMonitor = entranceRoomMonitorObj.GetComponent <AirConMonitor>();

        bookShelfController = bookShelf.GetComponent <BookShelfController>();

        padLockCamera.SetActive(false);
        playerUI.SetActive(false);

        audioSource = GetComponent <AudioSource>();
    }
Example #6
0
        public async void BulkInsert_No_Errors()
        {
            PasswordControllerMockFacade mock = new PasswordControllerMockFacade();

            var mockResponse = new CreateResponse <ApiPasswordResponseModel>(new FluentValidation.Results.ValidationResult());

            mockResponse.SetRecord(new ApiPasswordResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiPasswordRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiPasswordResponseModel> >(mockResponse));
            PasswordController controller = new PasswordController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var records = new List <ApiPasswordRequestModel>();

            records.Add(new ApiPasswordRequestModel());
            IActionResult response = await controller.BulkInsert(records);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var result = (response as OkObjectResult).Value as List <ApiPasswordResponseModel>;

            result.Should().NotBeEmpty();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiPasswordRequestModel>()));
        }
Example #7
0
        public async Task ResetPasswordAsync_ShouldBeOkResult()
        {
            // Arrange
            var user = new User
            {
                Id = new UserId()
            };

            TestMock.UserService.Setup(userManager => userManager.FindByIdAsync(It.IsAny <string>())).ReturnsAsync(user).Verifiable();

            TestMock.UserService.Setup(userManager => userManager.ResetPasswordAsync(It.IsAny <User>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(IdentityResult.Success)
            .Verifiable();

            var controller = new PasswordController(TestMock.UserService.Object, TestMock.ServiceBusPublisher.Object);

            // Act
            var result = await controller.ResetPasswordAsync(
                new ResetPasswordRequest
            {
                UserId   = new UserId(),
                Password = "******",
                Code     = "Code"
            });

            // Assert
            result.Should().BeOfType <OkResult>();

            TestMock.UserService.Verify(userManager => userManager.FindByIdAsync(It.IsAny <string>()), Times.Once);

            TestMock.UserService.Verify(userManager => userManager.ResetPasswordAsync(It.IsAny <User>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once);
        }
Example #8
0
        public void Index_UserNotNull_POST()
        {
            User user = new User {
                ID = 15, Email = "*****@*****.**"
            };

            mockUserService.Setup(m => m.ValidateEmailAddress(It.IsAny <string>()))
            .Returns(user);
            mockUserService.Setup(m => m.RandomCodeGenerator())
            .Returns(It.IsAny <string>());
            mockUserService.Setup(m => m.SendEmailAsync(It.IsAny <string>(),
                                                        It.IsAny <string>(), It.IsAny <string>())).Returns(Task.CompletedTask);


            var controller = new PasswordController(mockUserService.Object);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();
            controller.Url = controller.Url = new Mock <IUrlHelper>().Object;
            var    result = controller.Index("*****@*****.**") as RedirectToActionResult;
            object id;

            result.RouteValues.TryGetValue("id", out id);
            Assert.Equal("Reset", result.ActionName);
            Assert.Equal(15, (long)id);
        }
Example #9
0
        public void Reset_ModelStateIsValid_POST()
        {
            User user = new User
            {
                ID        = 15,
                Email     = "*****@*****.**",
                ResetCode = "ZABGH52Y"
            };

            PasswordResetViewModel model = new PasswordResetViewModel
            {
                ID              = 15,
                Email           = "*****@*****.**",
                Password        = "******",
                ResetCode       = "ZABGH52Y",
                ConfirmPassword = "******"
            };

            mockUserService.Setup(m => m.Find(It.IsAny <long>())).Returns(user);
            mockUserService.Setup(m => m.GetEncryptedPassword(It.IsAny <string>()))
            .Returns(It.IsAny <string>());

            var controller = new PasswordController(mockUserService.Object);

            var result = controller.Reset(model) as RedirectToActionResult;

            Assert.Equal("ResetSuccess", result.ActionName);
        }
Example #10
0
        public void Reset_WrongResetCode_POST()
        {
            User user = new User
            {
                ID        = 15,
                Email     = "*****@*****.**",
                ResetCode = "ZABGH52Y"
            };

            PasswordResetViewModel model = new PasswordResetViewModel
            {
                ID              = 15,
                Email           = "*****@*****.**",
                Password        = "******",
                ResetCode       = "ZABGH52X",
                ConfirmPassword = "******"
            };

            mockUserService.Setup(m => m.Find(It.IsAny <long>())).Returns(user);

            var controller  = new PasswordController(mockUserService.Object);
            var result      = controller.Reset(model) as ViewResult;
            var modelResult = result.Model as PasswordResetViewModel;

            Assert.Equal(15, modelResult.ID);
            Assert.Equal("*****@*****.**", modelResult.Email);
        }
Example #11
0
        public async Task Post(bool returnValue)
        {
            const string password    = "******";
            const int    userId      = 123;
            var          userManager = new Mock <IUserManager>();

            userManager.Setup(c => c.UpdatePassword(userId, password))
            .Returns(Task.FromResult(returnValue));

            var sut = new PasswordController(userManager.Object);

            sut.Token = new AuthToken
            {
                Token      = "token",
                UserId     = userId,
                ValidUntil = DateTime.Now.AddDays(1),
                IsVerified = true
            };

            var result = await sut.Post(new PasswordChangeRequest
            {
                Password = password,
                DeviceId = "deviceId"
            });

            Assert.AreEqual(returnValue, result);
        }
Example #12
0
        public async void Patch_No_Errors()
        {
            PasswordControllerMockFacade mock = new PasswordControllerMockFacade();
            var mockResult = new Mock <UpdateResponse <ApiPasswordResponseModel> >();

            mockResult.SetupGet(x => x.Success).Returns(true);
            mock.ServiceMock.Setup(x => x.Update(It.IsAny <int>(), It.IsAny <ApiPasswordRequestModel>()))
            .Callback <int, ApiPasswordRequestModel>(
                (id, model) => model.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"))
                )
            .Returns(Task.FromResult <UpdateResponse <ApiPasswordResponseModel> >(mockResult.Object));
            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiPasswordResponseModel>(new ApiPasswordResponseModel()));
            PasswordController controller = new PasswordController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiPasswordModelMapper());

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var patch = new JsonPatchDocument <ApiPasswordRequestModel>();

            patch.Replace(x => x.ModifiedDate, DateTime.Parse("1/1/1987 12:00:00 AM"));

            IActionResult response = await controller.Patch(default(int), patch);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            mock.ServiceMock.Verify(x => x.Update(It.IsAny <int>(), It.IsAny <ApiPasswordRequestModel>()));
        }
        private async void CreateAccountButton_OnClicked(object sender, EventArgs e)
        {
            try
            {
                if (CreatePasswordEntry.Text.Equals(CreatePasswordConfirmationEntry.Text))
                {
                    PasswordController passwordController = new PasswordController();
                    IUserRestService   userRestService    = new UserRestService();

                    User user = new User();
                    user.UserName     = CreateUserNameEntry.Text;
                    user.Salt         = passwordController.GenerateSalt();
                    user.HashPassword = passwordController.GenerateHashedPassword(CreatePasswordEntry.Text, Encoding.ASCII.GetBytes(user.Salt));
                    user.UserType     = new UserType
                    {
                        TypeName = "personal"
                    };

                    await userRestService.Create(user);

                    //Debug.WriteLine("Hashes and salt be here: " + user.HashPassword + " " + user.Salt);
                }
                else
                {
                    await DisplayAlert("Fejl", "Passwords are not equals", "OK");
                }
            }
            catch (FaultException <Exception> exc)
            {
                await DisplayAlert("Fejl", exc.Message, "OK");
            }
        }
Example #14
0
        public async Task ResetPasswordAsync_WhenUserNotFound_ShouldBeOkResult()
        {
            // Arrange
            TestMock.UserService.Setup(userManager => userManager.FindByIdAsync(It.IsAny <string>())).Verifiable();

            TestMock.UserService.Setup(userManager => userManager.ResetPasswordAsync(It.IsAny <User>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(
                IdentityResult.Failed(
                    new IdentityError
            {
                Code        = "code",
                Description = "description"
            }))
            .Verifiable();

            var controller = new PasswordController(TestMock.UserService.Object, TestMock.ServiceBusPublisher.Object);

            // Act
            var result = await controller.ResetPasswordAsync(
                new ResetPasswordRequest
            {
                UserId   = new UserId(),
                Password = "******",
                Code     = "Code"
            });

            // Assert
            result.Should().BeOfType <OkResult>();

            TestMock.UserService.Verify(userManager => userManager.FindByIdAsync(It.IsAny <string>()), Times.Once);

            TestMock.UserService.Verify(userManager => userManager.ResetPasswordAsync(It.IsAny <User>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never);
        }
Example #15
0
        public void IsValid_WithInvalidRequestValue_ReturnsBadRequest(string value)
        {
            var controller = new PasswordController(passwordService: null);

            var result = controller.IsValid(value);

            Assert.IsType <BadRequestResult>(result.Result);
        }
Example #16
0
        public void Index()
        {
            PasswordController controller = new PasswordController();
            ViewResult         result     = controller.Index() as ViewResult;

            // Assert
            Assert.AreEqual(result.ViewBag.Something, "Something");
        }
Example #17
0
        public void SetUp()
        {
            this.userService           = new Mock <IUserService>();
            this.appEnvironmentService = new Mock <IAppEnvironmentService>();
            this.logger = new Mock <ILogger>();

            this.controller = new PasswordController(this.userService.Object, this.logger.Object, this.appEnvironmentService.Object);
            SetControllerContext(this.controller);
        }
Example #18
0
        public void GetCriteria()
        {
            var sut    = new PasswordController(Mock.Of <IUserManager>());
            var result = sut.Get();

            Assert.AreEqual(6, result.MinimumLength);
            Assert.AreEqual(1, result.MinimumAlphabetic);
            Assert.AreEqual(1, result.MinimumNumeric);
        }
Example #19
0
        public void IsValid_WithValidRequestValue_CallsPasswordService()
        {
            var mockPasswordService = new Mock <IPasswordService>();
            var controller          = new PasswordController(mockPasswordService.Object);
            var validPassword       = "******";

            controller.IsValid(validPassword);

            mockPasswordService.Verify(mock => mock.IsValid(validPassword), Times.Once());
        }
Example #20
0
        public void PostValidatePassword(bool expected, string password)
        {
            var sut    = new PasswordController(Mock.Of <IUserManager>());
            var result = sut.PostValidatePassword(new PasswordChangeRequest
            {
                Password = password,
                DeviceId = "deviceId"
            });

            Assert.AreEqual(expected, result);
        }
        private void BtnGetPasswords_Click(object sender, EventArgs e)
        {
            LbUrls.Items.Clear();
            List <Password> passwords = PasswordController.GetChromePasswords();

            foreach (var password in passwords)
            {
                LbUrls.Items.Add(password);
                LbUrls.DisplayMember = "LoginUrl";
            }
        }
        public void ValidateChangePassword_PasswordController_MoqTest()
        {
            PasswordMessage.Add(UsernameCannotBeBlankViolation);
            PasswordMessage.Add(PasswordCannotBeBlankViolation);

            mockIPasswordQueryService.Setup(x => x.GetPolicyViolations(It.IsAny <Guid>(), null))
            .Returns(PasswordMessage);
            var           controller   = new PasswordController(mockIPasswordQueryService.Object);
            List <string> actionResult = controller.ValidateChangePassword(It.IsAny <ChangePasswordRequest>());

            Assert.AreEqual(PasswordMessage[0], actionResult[0]);
        }
        private async void SignInButton_OnClicked(object sender, EventArgs e)
        {
            try
            {
                var uName = UserNameEntry.Text;
                var pWord = PasswordEntry.Text;
                PasswordController pCtrl = new PasswordController();
                bool status = await pCtrl.VerifyLogin(uName, pWord);

                if (status)
                {
                    IUserRestService restService = new UserRestService();
                    User             user        = await restService.FindByUserName(uName);

                    if (user != null)
                    {
                        _tabbedMapMainPage = new TabbedMapMainPage
                        {
                            User = user
                        };
                        _tabbedMapMainPage.StartUpWithUser();
                        await Navigation.PushAsync(_tabbedMapMainPage);

                        Navigation.RemovePage(this);
                    }
                }
            }
            catch (EmptyInputException exc)
            {
                await DisplayAlert("Fejl", exc.ReturnMessage, "OK");
            }
            catch (UserOrPasswordException exc)
            {
                await DisplayAlert("Fejl", exc.ReturnMessage, "OK");
            }
            catch (FaultException <UserOrPasswordException> exc)
            {
                await DisplayAlert("Fejl", exc.Message, "OK");
            }
            catch (FaultException <UserNotFoundException> exc)
            {
                await DisplayAlert("Fejl", exc.Message, "OK");
            }
            catch (FaultException <Exception> exc)
            {
                await DisplayAlert("Fejl", exc.Message, "OK");
            }
            catch (Exception exc)
            {
                await DisplayAlert("Fejl", exc.Message, "OK");
            }
        }
Example #24
0
        public async Task ResetPassword_redirects_to_error_view_when_passwordobj_is_null()
        {
            //Arrange
            var controller = new PasswordController(_configuration, multitenantService, _contextAccessor);

            //Act
            var result = await controller.ResetPassword(null);

            //Assert
            var viewResult = Assert.IsType <ViewResult>(result); //Asserting that the return is a View

            Assert.Equal("ErrorPage", viewResult.ViewName);      //Asserting that the returned view is "Error Page"
        }
Example #25
0
        public async Task Reset_redirects_to_error_view_when_slug_is_null()
        {
            //Arrange
            var controller = new PasswordController(_bosAuthClient);

            //Act
            var result = await controller.Reset(null);

            //Assert
            var viewResult = Assert.IsType <ViewResult>(result); //Asserting that the return is a View

            Assert.Equal("ErrorPage", viewResult.ViewName);      //Asseting that the returned view is "Error Page"
        }
Example #26
0
        /// <summary>
        /// Аутентификация пользоватля в системе
        /// </summary>
        /// <param name="datAutorizationUserData">Данные пользователя для аутентификации</param>
        public void Autontefication([CanBeNull] AutorizationUserData datAutorizationUserData)
        {
            if (string.IsNullOrEmpty(datAutorizationUserData?.UserLoginName) ||
                string.IsNullOrEmpty(datAutorizationUserData.PasswordString))
            {
                return;
            }

            AutorizationUserData = datAutorizationUserData;
            //При авторизации также получим данные пользователя
            PasswordController.GetSystemUserData(AutorizationUserData, out Employee userData);
            //Вернем данные пользователя
            WorkingUserData = userData;
        }
Example #27
0
        public void IsValid_WithValidPassword_ReturnsTrue()
        {
            var validPassword   = "******";
            var passwordService = new Mock <IPasswordService>();

            passwordService
            .Setup(e => e.IsValid(validPassword))
            .Returns(true);
            var controller = new PasswordController(passwordService.Object);

            var result = controller.IsValid(validPassword);

            Assert.True(result.Value);
        }
Example #28
0
        public async Task Reset_redirects_to_error_view_when_slug_is_invalid()
        {
            //Arrange
            var controller = new PasswordController(_bosAuthClient);

            //Act
            var result = await controller.Reset("random-slug-string");

            //Assert
            var viewResult = Assert.IsType <ViewResult>(result); //Asserting that the return is a View

            Assert.Equal("ResetPassword", viewResult.ViewName);  //Asseting that the returned Controller is "ResetPassword"
            Assert.True(controller.ViewBag.Message != null);     //
        }
Example #29
0
        public void SetUp()
        {
            this._userService             = new Mock <IUserService>();
            this._passwordHistoryService  = new Mock <IPasswordHistoryService>();
            this._securityQuestionService = new Mock <ISecurityQuestionService>();
            this._securityAnswerService   = new Mock <ISecurityAnswerService>();
            _logger = new Mock <ILogger>();

            this._controller = new PasswordController(this._userService.Object,
                                                      this._passwordHistoryService.Object,
                                                      this._securityQuestionService.Object,
                                                      this._securityAnswerService.Object,
                                                      this._logger.Object);
        }
Example #30
0
        public void GotBackToLogin_returns_login_view()
        {
            //Arrange
            var controller = new PasswordController(_bosAuthClient);

            //Act
            var result = controller.GotBackToLogin();

            //Assert
            var redirectResult = Assert.IsType <RedirectToActionResult>(result); //Asserting that the return is a View

            Assert.Equal("Auth", redirectResult.ControllerName);                 //Asseting that the returned Controller is "Auth"
            Assert.Equal("Index", redirectResult.ActionName);                    //Asseting that the Action Methond of the controller is "Index"
        }