예제 #1
0
        public void SymmetricEncryption()
        {
            var cipherText = CryptoKey.Encrypt(PlainText, PassPhrase);

            var plainText = CryptoKey.Decrypt(cipherText, PassPhrase);

            Assert.AreEqual(plainText, PlainText);
        }
예제 #2
0
        protected void LoginGrid_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridError.Text = string.Empty;

            var id = LoginGrid?.DataKeys[e.RowIndex]?.Value;

            if (id == null)
            {
                return;
            }

            var newName   = e.NewValues["UserName"].ToString();
            var newPw     = e.NewValues["Password"].ToString();
            var encrypted = CryptoKey.Encrypt(newPw, Keys.Biscuits);

            var login = _serverLoginDal.Get((int)id);

            if (login.UserName == newName && login.PasswordHash == encrypted)
            {
                LoginGrid.EditIndex = -1;
                return;
            }

            try
            {
                _serverLoginDal.Update(new ServerLogin
                {
                    ServerLoginId = (int)id,
                    ServerId      = login.ServerId,
                    DepartmentId  = login.DepartmentId,
                    UserName      = login.UserName,
                    PasswordHash  = encrypted
                });
            }
            catch (ValidationException ex)
            {
                GridError.Text = ex.Message;
            }
            catch (NotFoundException ex)
            {
                GridError.Text = ex.Message;
            }
            catch (Exception)
            {
                GridError.Text = "An error occured while updating the department.";
            }
            finally
            {
                LoginGrid.EditIndex = -1;
                RefreshGrid();
            }
        }
예제 #3
0
        protected void addLoginSave_OnClick(object sender, EventArgs e)
        {
            var serverId     = int.Parse(ServerDropDown.SelectedValue);
            var departmentId = int.Parse(DepartmentDropDown.SelectedValue);

            var error = ValidateNewLogin(serverId, departmentId);

            var department = _departmentDal.Get(departmentId);

            if (department.Servers.All(s => s.ServerId != serverId))
            {
                LoginErrorMessage.Text = "Department does not have access to server.";
                AddLoginPopupExtender.Show();
                return;
            }

            if (!string.IsNullOrEmpty(error))
            {
                LoginErrorMessage.Text = error;
                AddLoginPopupExtender.Show();
                return;
            }

            try
            {
                var encryptedPassword = CryptoKey.Encrypt(UserPasswordInput.Text, Keys.Biscuits);

                _serverLoginDal.Create(new ServerLogin
                {
                    ServerId     = serverId,
                    DepartmentId = departmentId,
                    UserName     = UserNameInput.Text,
                    PasswordHash = encryptedPassword
                });

                LoginErrorMessage.Text = string.Empty;
                UserNameInput.Text     = string.Empty;
                UserPasswordInput.Text = string.Empty;
                UserConfirmInput.Text  = string.Empty;

                InitializeDropdowns();
                RefreshGrid();
            }
            catch (Exception)
            {
                LoginErrorMessage.Text = "Error occured while creating login.";
                AddLoginPopupExtender.Show();
            }
        }