示例#1
0
 private void AddTeacherPasswordButton_Click(object sender, EventArgs e)
 {
     if (OldPassTextBox.Text.Length == 0 ||
         NewPassTextBox.Text.Length == 0 ||
         ConfirmedNewPassTextBox.Text.Length == 0)
     {
         Warning();
     }
     else
     {
         if (OldPassTextBox.Text == NewPassTextBox.Text)
         {
             MessageBox.Show("Unesite novu lozinku koja se razlikuje od stare !");
         }
         else if (Encrypt.hashPassword(OldPassTextBox.Text) == CurrentUser.Password && NewPassTextBox.Text == ConfirmedNewPassTextBox.Text)
         {
             bool isChanged = UsersRepository.ChangePassword(CurrentUser.Id, OldPassTextBox.Text, NewPassTextBox.Text, ConfirmedNewPassTextBox.Text);
             if (isChanged == true)
             {
                 PasswordPanel.Hide();
                 UserSettingsButton.Hide();
             }
         }
         else if (NewPassTextBox.Text != ConfirmedNewPassTextBox.Text)
         {
             MessageBox.Show("Nove lozinke se ne poklapaju !");
         }
         else
         {
             MessageBox.Show("Pogrešna lozinka !");
         }
     }
 }
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {
                // ChangePassword will throw an exception rather
                // than return false in certain failure scenarios.
                bool changePasswordSucceeded;
                try
                {
                    //userRepo.GetUser(User.Identity.Name, userIsOnline: true);
                    changePasswordSucceeded = userRepo.ChangePassword(model.OldPassword, model.NewPassword);
                }
                catch (Exception)
                {
                    changePasswordSucceeded = false;
                }

                if (changePasswordSucceeded)
                {
                    return(RedirectToAction("ChangePasswordSuccess"));
                }
                else
                {
                    ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#3
0
        public async Task <ActionResult> ResetPasswordConfirmed(string submitButton, string id)
        {
            if (submitButton == "yes")
            {
                await repository.ChangePassword(id);
            }

            return(RedirectToAction("Index"));
        }
        public void ShouldChangePassword()
        {
            User result = Datalayer.Sql.Tests.Helper.CreateUser(_connectionString, Datalayer.Sql.Tests.Helper.NewUser());

            repository.ChangePassword(result.Id, "NewPass");
            User gottenUser = new UsersRepository(_connectionString).Get(result.Id);

            Assert.AreEqual("NewPass", gottenUser.Password);
        }
示例#5
0
        public void ShouldChangePassword()
        {
            User user = Create.User();

            _usersRepository.ChangePassword(user.ID, "password2");

            User gottenUser = _db.Users.First(u => u.ID == user.ID);

            Assert.AreEqual("password2", gottenUser.PasswordHash);
        }
示例#6
0
        public IActionResult ChangePassword(ChangePasswordModel model)
        {
            var currentUser = _userRepository.Get(GetUserId());

            if (!PasswordHelper.ValidatePassword(model.OldPassword, currentUser))
            {
                Unauthorized();
            }

            _userRepository.ChangePassword(currentUser, model.NewPassword);

            _userRepository.Update(currentUser);

            return(NoContent());
        }
        public ActionResult ChangePassword(UserProfileModel model)
        {
            if (UsersRepository.ValidatePasswordIsCorrect(UserContextHelper.GetUserContextModel().Email,
                                                          model.OldPassword) != null)
            {
                if (UsersRepository.ChangePassword(model.NewPassword, UserContextHelper.GetUserContextModel().ID))
                {
                    ModelState.Clear();
                    ViewBag.SuccessMessages = "Zmiana hasła zakończona pomyślnie";
                }
            }

            model = UsersRepository.GetUserProfileModel(UserContextHelper.GetUserContextModel().ID);
            ViewBag.ErrorMessages = UsersRepository.ErrorList;
            return(View("UserProfile", model));
        }
示例#8
0
 async private void buttonChange_Click(object sender, RoutedEventArgs e)
 {
     if (newPassword.Password != newPasswordRepeat.Password)
     {
         MessageBox.Show("Пароли не совпадают");
     }
     else if (newPassword.Password == "")
     {
         MessageBox.Show("Пароль не может быть пустым");
     }
     else if (ActiveUser.UserPassword != oldPassword.Text)
     {
         MessageBox.Show("Неверный старый пароль");
     }
     else
     {
         UsersRepository ur = UsersRepository.Initialize();
         await Task.Run(() => { ur.ChangePassword(newPassword.Password); });
     }
 }
示例#9
0
 private void AddDirectorPasswordButton_Click(object sender, EventArgs e)
 {
     if (OldPassTextBox.Text.Length == 0 ||
         NewPassTextBox.Text.Length == 0 ||
         ConfirmedNewPassTextBox.Text.Length == 0)
     {
         warning();
     }
     else
     {
         if (OldPassTextBox.Text == NewPassTextBox.Text)
         {
             MessageBox.Show("Unesite novu lozinku koja se razlikuje od stare !");
         }
         else if (Encrypt.hashPassword(OldPassTextBox.Text) == CurrentUser.Password && NewPassTextBox.Text == ConfirmedNewPassTextBox.Text)
         {
             bool isChanged = UsersRepository.ChangePassword(CurrentUser.Id, OldPassTextBox.Text, NewPassTextBox.Text, ConfirmedNewPassTextBox.Text);
             if (isChanged == true)
             {
                 ChoseComboBox.SelectedIndex = 0;
                 AdminPanel.Show();
                 label2.Show();
                 ChoseComboBox.Show();
                 TeacherPanel.Hide();
                 StudentAndParentPanel.Hide();
                 DepartmentsPanel.Hide();
                 PasswordPanel.Hide();
                 UserSettingsButton.Hide();
             }
         }
         else if (NewPassTextBox.Text != ConfirmedNewPassTextBox.Text)
         {
             MessageBox.Show("Nove lozinke se ne poklapaju !");
         }
         else
         {
             MessageBox.Show("Pogrešna lozinka !");
         }
     }
 }
        public void ShouldChangePasswordOfUser()
        {
            //arrange
            var user = new User
            {
                Name    = "testUser",
                Picture = new byte[] {}
            };
            var login    = "******";
            var password = "******";

            //act
            var repository = new UsersRepository(ConnectionString);
            var result     = repository.Create(user, login, password);

            _tempUsers.Add(result.Id);
            repository.ChangePassword(result.Id, password, "newPassword");
            result = repository.Get(result.Id);

            //asserts
            Assert.AreEqual(result.LogInfo.Password, AuthRepository.GetHashString("newPassword"));
        }
示例#11
0
 public void ChangePassword([FromBody] User user)
 => _usersRepository.ChangePassword(user.ID, user.PasswordHash);
示例#12
0
 public void ChangePassword([FromBody] User user)
 {
     usersRepository.ChangePassword(user.Id, user.Password);
 }