Пример #1
0
        void OnDeleteRole(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to delete the role " + RoleName + " ?", "Credentials Manager", MessageBoxButtons.OKCancel);

            if (result == DialogResult.OK)
            {
                IRoleManager roleManager = UserManagerProviderFactory.CreateRoleManager(); // new AspNetSqlProviderService(ServiceAddress);
                try
                {
                    bool deleted = roleManager.DeleteRole(ApplicationName, RoleName, m_ThrowIfPopulatedCheckBox.Checked);
                    if (deleted == false)
                    {
                        MessageBox.Show("Encountered an error trying to delete role " + m_RolesListView.CurrentListViewItem, "Credentials Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        m_RolesListView.RemoveItem(RoleName);
                        RefreshUsersForRoleComboBox();
                        RefreshRolesForUserComboBox();
                        RefreshRolePageButtons();
                    }
                }
                catch (SoapException exception)
                {
                    if (exception.Message.Contains("This role cannot be deleted because there are users present in it"))
                    {
                        MessageBox.Show("Failed to delete role " + m_RolesListView.CurrentListViewItem + " because it was populated.", "Credentials Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
Пример #2
0
        void OnResetPassword(object sender, EventArgs e)
        {
            Debug.Assert(EnablePasswordReset);

            if (RequiresQuestionAndAnswer)
            {
                ResetWithQuestionDialog dialog = new ResetWithQuestionDialog(ServiceAddress, ApplicationName, UserName);
                dialog.ShowDialog();
            }
            else
            {
                IPasswordManager passwordManager = UserManagerProviderFactory.CreatePasswordManager(); // new AspNetSqlProviderService(ServiceAddress);
                string           newPassword     = null;
                try
                {
                    newPassword = passwordManager.ResetPassword(ApplicationName, UserName);
                    Clipboard.SetText(newPassword);
                }
                catch (SoapException exception)
                {
                    if (exception.Message.Contains("The user account has been locked out"))
                    {
                        MessageBox.Show("The user account has been locked out", "Credentials Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    throw;
                }
                MessageBox.Show("Generated password: "******" " + Environment.NewLine + "The password is avaiable on the clipboard as well.", "Credentials Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        public AuthorizationDialog(string url, string application, string user) : this()
        {
            m_Url = url;
            m_ApplicationTextBox.Text = application;
            m_UserComboBox.Text       = user;

            IRoleManager roleManager = UserManagerProviderFactory.CreateRoleManager();

            string[] roles = roleManager.GetRolesForUser(application, user);

            m_RoleComboBox.Items.AddRange(roles);
            if (roles.Length > 0)
            {
                m_RoleComboBox.Text = roles[roles.Length - 1];
            }

            IMembershipManager membershipManager = roleManager as IMembershipManager;

            string[] users = membershipManager.GetAllUsers(application);

            m_UserComboBox.Items.AddRange(users);
            if (users.Length > 0)
            {
                m_UserComboBox.Text = users[users.Length - 1];
            }
        }
Пример #4
0
        void RefreshPasswordsPage()
        {
            if (ApplicationName == String.Empty)
            {
                m_PasswordReset.Text                  = "-";
                m_PasswordRetrieval.Text              = "-";
                m_MaxInvalidAttempts.Text             = "-";
                m_MinNonAlphanumeric.Text             = "-";
                m_MinLength.Text                      = "-";
                m_AttemptWindow.Text                  = "-";
                m_PasswordRegularExpression.Text      = "-";
                m_RequiresQuestionAndAnswerLabel.Text = "-";
                m_LengthTextBox.Text                  = String.Empty;
                m_NonAlphanumericTextBox.Text         = String.Empty;
                m_GeneratePasswordMenuItem.Enabled    = m_GeneratePassword.Enabled = false;
                return;
            }
            m_GeneratePasswordMenuItem.Enabled = m_GeneratePassword.Enabled = true;

            IPasswordManager passwordManager = UserManagerProviderFactory.CreatePasswordManager(); // new AspNetSqlProviderService(ServiceAddress);

            if (passwordManager.EnablePasswordReset(ApplicationName))
            {
                EnablePasswordReset  = true;
                m_PasswordReset.Text = "Yes";
            }
            else
            {
                EnablePasswordReset  = false;
                m_PasswordReset.Text = "No";
            }
            if (passwordManager.EnablePasswordRetrieval(ApplicationName))
            {
                EnablePasswordRetrieval  = true;
                m_PasswordRetrieval.Text = "Yes";
            }
            else
            {
                EnablePasswordRetrieval  = false;
                m_PasswordRetrieval.Text = "No";
            }
            m_MaxInvalidAttempts.Text        = passwordManager.GetMaxInvalidPasswordAttempts(ApplicationName).ToString();
            m_MinNonAlphanumeric.Text        = passwordManager.GetMinRequiredNonAlphanumericCharacters(ApplicationName).ToString();
            m_MinLength.Text                 = passwordManager.GetMinRequiredPasswordLength(ApplicationName).ToString();
            m_AttemptWindow.Text             = passwordManager.GetPasswordAttemptWindow(ApplicationName).ToString();
            m_PasswordRegularExpression.Text = passwordManager.GetPasswordStrengthRegularExpression(ApplicationName);
            if (passwordManager.RequiresQuestionAndAnswer(ApplicationName))
            {
                RequiresQuestionAndAnswer             = true;
                m_RequiresQuestionAndAnswerLabel.Text = "Yes";
            }
            else
            {
                RequiresQuestionAndAnswer             = false;
                m_RequiresQuestionAndAnswerLabel.Text = "No";
            }

            m_LengthTextBox.Text          = m_MinLength.Text;
            m_NonAlphanumericTextBox.Text = m_MinNonAlphanumeric.Text;
        }
Пример #5
0
        void OnRemoveUserFromRole(object sender, EventArgs e)
        {
            string role = m_RolesListView.CurrentListViewItem;

            Debug.Assert(!String.IsNullOrEmpty(role));
            IRoleManager roleManager = UserManagerProviderFactory.CreateRoleManager(); // new AspNetSqlProviderService(ServiceAddress);
            IUserManager userManager = roleManager as IUserManager;

            Debug.Assert(userManager != null);

            if (userManager.IsInRole(ApplicationName, UserToAssign, role))
            {
                DialogResult result = MessageBox.Show("Are you sure you want to remove the user " + UserToAssign + " from the role " + m_RolesListView.CurrentListViewItem + " ?", "Credentials Manager", MessageBoxButtons.OKCancel);
                if (result == DialogResult.OK)
                {
                    roleManager.RemoveUserFromRole(ApplicationName, UserToAssign, role);
                    RefreshRolesForUserComboBox();
                    RefreshUsersForRoleComboBox();
                    RefreshRolePageButtons();
                }
            }
            else
            {
                MessageBox.Show("The user " + UserToAssign + " is not a member of the role " + m_RolesListView.CurrentListViewItem, "Credentials Manager", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            }
        }
Пример #6
0
        void OnDeleteUser(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to delete the user " + UserName + " ?", "Credentials Manager", MessageBoxButtons.OKCancel);

            if (result == DialogResult.OK)
            {
                IMembershipManager membershipManager = UserManagerProviderFactory.CreateMembershipManager(); // new AspNetSqlProviderService(ServiceAddress);
                bool deleted = membershipManager.DeleteUser(ApplicationName, UserName, m_RelatedDataCheckBox.Checked);
                if (deleted == false)
                {
                    MessageBox.Show("Encountered an error trying to delete user " + UserName, "Credentials Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    //Upade the roles page
                    m_UsersToAssignListView.RemoveItem(UserName);
                    RefreshUsersForRoleComboBox();
                    RefreshRolesForUserComboBox();
                    RefreshRolePageButtons();

                    //Update the users list
                    m_UsersListView.RemoveItem(UserName);
                    RefreshUserStatus();
                    RefreshUsersPageButtonsAndMenuItems();
                }
            }
        }
Пример #7
0
        void OnCreateRole(object sender, EventArgs e)
        {
            IRoleManager roleManager = UserManagerProviderFactory.CreateRoleManager(); // new AspNetSqlProviderService(m_Url);

            string[]           roles  = roleManager.GetAllRoles(m_Application);
            Predicate <string> exists = delegate(string role)
            {
                return(role == m_RoleTextBox.Text);
            };

            if (Array.Exists(roles, exists))
            {
                m_RoleValidator.SetError(m_RoleTextBox, "Role already exists");
                return;
            }
            m_RoleValidator.Clear();
            if (m_RoleTextBox.Text == String.Empty)
            {
                m_RoleValidator.SetError(m_RoleTextBox, "Role cannot be empty");
                return;
            }
            m_RoleValidator.Clear();
            roleManager.CreateRole(m_Application, m_RoleTextBox.Text);
            m_Roles.Add(m_RoleTextBox.Text);
            m_CreatedRolesListView.AddItem(m_RoleTextBox.Text, true);
            m_RoleTextBox.Focus();
            m_RoleTextBox.Text = String.Empty;
        }
Пример #8
0
 void RefreshRolesForUserComboBox()
 {
     string[] roles = null;
     if (String.IsNullOrEmpty(UserToAssign) == false)
     {
         IRoleManager roleManager = UserManagerProviderFactory.CreateRoleManager(); // new AspNetSqlProviderService(ServiceAddress);
         roles = roleManager.GetRolesForUser(ApplicationName, UserToAssign);
     }
     m_RolesForUserComboBox.RefreshComboBox(UserToAssign, roles);
 }
        public ResetWithQuestionDialog(string url, string application, string user)
        {
            InitializeComponent();

            m_Url                  = url;
            m_Application          = application;
            m_UserNameTextBox.Text = user;

            m_PasswordManager = UserManagerProviderFactory.CreatePasswordManager(); // new AspNetSqlProviderService(m_Url);
            m_PasswordQuestionTextBox.Text = m_PasswordManager.GetPasswordQuestion(application, user);
        }
Пример #10
0
        void RefreshUsersForRoleComboBox()
        {
            string[] users = null;

            if (String.IsNullOrEmpty(RoleName) == false)
            {
                IRoleManager roleManager = UserManagerProviderFactory.CreateRoleManager(); // new AspNetSqlProviderService(ServiceAddress);
                users = roleManager.GetUsersInRole(ApplicationName, RoleName);
            }
            m_UsersInRoleComboBox.RefreshComboBox(RoleName, users);
        }
Пример #11
0
        void RefreshUsersListView()
        {
            m_UsersListView.ClearItems();
            if (ApplicationName == String.Empty)
            {
                return;
            }
            IMembershipManager membershipManager = UserManagerProviderFactory.CreateMembershipManager(); // new AspNetSqlProviderService(ServiceAddress);

            string[] users = membershipManager.GetAllUsers(ApplicationName);
            m_UsersListView.AddItems(users, true);
        }
Пример #12
0
 void RefreshApplicationListView()
 {
     m_ApplicationListView.ClearItems();
     string[] applications = new string[] { };
     if (ValidAddress)
     {
         IApplicationManager applicationManager = UserManagerProviderFactory.CreateApplicationManager(); // new AspNetSqlProviderService(ServiceAddress);
         applications = applicationManager.GetApplications();
     }
     m_ApplicationListView.AddItems(applications, true);
     SelectedApplicationChanged();
 }
Пример #13
0
        void OnGeneratePassword(object sender, EventArgs e)
        {
            int length          = Convert.ToInt32(m_LengthTextBox.Text);
            int nonAlphanumeric = Convert.ToInt32(m_NonAlphanumericTextBox.Text);

            IPasswordManager passwordManager = UserManagerProviderFactory.CreatePasswordManager(); // new AspNetSqlProviderService(ServiceAddress);
            string           password        = passwordManager.GeneratePassword(ApplicationName, length, nonAlphanumeric);

            Clipboard.SetText(password);

            MessageBox.Show("Generated password: "******" " + Environment.NewLine + "The password is avaiable on the clipboard as well.", "Credentials Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        public ChangePasswordDialog(string url, string application, string user)
        {
            InitializeComponent();

            m_Url                  = url;
            m_Application          = application;
            m_UserNameTextBox.Text = user;

            m_PasswordManager = UserManagerProviderFactory.CreatePasswordManager(); // new AspNetSqlProviderService(m_Url);
            m_PasswordQuestionTextBox.Text = m_PasswordManager.GetPasswordQuestion(application, user);

            m_PasswordAnswerTextBox.Enabled = m_PasswordManager.RequiresQuestionAndAnswer(application);
        }
Пример #15
0
        void RefreshUserStatus()
        {
            if (ApplicationName == String.Empty)
            {
                m_UsersOnline.Text      = "-";
                m_OnlineTimeWindow.Text = "-";
                return;
            }
            IMembershipManager membershipManager = UserManagerProviderFactory.CreateMembershipManager(); // new AspNetSqlProviderService(ServiceAddress);

            m_UsersOnline.Text      = membershipManager.GetNumberOfUsersOnline(ApplicationName).ToString();
            m_OnlineTimeWindow.Text = membershipManager.UserIsOnlineTimeWindow(ApplicationName).ToString();
        }
Пример #16
0
        void RefreshRolesListView()
        {
            m_RolesListView.ClearItems();
            if (ApplicationName == String.Empty)
            {
                return;
            }
            IRoleManager roleManager = UserManagerProviderFactory.CreateRoleManager(); // new AspNetSqlProviderService(ServiceAddress);

            string[] roles = roleManager.GetAllRoles(ApplicationName);

            m_RolesListView.AddItems(roles, true);
        }
Пример #17
0
        void OnDeleteAllApplications(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to delete all applications?", "Credentials Manager", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

            if (result == DialogResult.OK)
            {
                IApplicationManager applicationManager = UserManagerProviderFactory.CreateApplicationManager(); // new AspNetSqlProviderService(ServiceAddress);
                applicationManager.DeleteAllApplications();
                m_ApplicationListView.ClearItems();

                SelectedApplicationChanged();
            }
            RefreshApplicationButtons();
        }
Пример #18
0
        void OnDeleteAllRoles(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to delete all roles from the application?", "Credentials Manager", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

            if (result == DialogResult.OK)
            {
                IRoleManager roleManager = UserManagerProviderFactory.CreateRoleManager(); // new AspNetSqlProviderService(ServiceAddress);
                roleManager.DeleteAllRoles(ApplicationName, m_ThrowIfPopulatedCheckBox.Checked);

                m_RolesListView.ClearItems();
                RefreshUsersForRoleComboBox();
                RefreshRolesForUserComboBox();
                RefreshRolePageButtons();
            }
        }
Пример #19
0
        void OnDeleteApplication(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to delete the " + ApplicationName + " application? This will remove all users and roles already defined.", "Credentials Manager", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

            if (result == DialogResult.OK)
            {
                IApplicationManager applicationManager = UserManagerProviderFactory.CreateApplicationManager(); // new AspNetSqlProviderService(ServiceAddress);
                applicationManager.DeleteApplication(ApplicationName);

                m_ApplicationListView.RemoveItem(ApplicationName);

                SelectedApplicationChanged();
                RefreshApplicationButtons();
            }
        }
        void OnLogin(object sender, EventArgs e)
        {
            IUserManager userManager = UserManagerProviderFactory.CreateUserManager(); // new AspNetSqlProviderService(m_Url);
            bool         isInRole    = false;

            isInRole = userManager.IsInRole(m_ApplicationTextBox.Text, m_UserComboBox.Text, m_RoleComboBox.Text);
            if (isInRole)
            {
                MessageBox.Show(this, "Successful Authorization", "Credentials Manager", MessageBoxButtons.OK);
            }
            else
            {
                MessageBox.Show(this, "User is not a member of the specified role", "Credentials Manager", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }
Пример #21
0
        void OnLogin(object sender, EventArgs e)
        {
            IUserManager userManager   = UserManagerProviderFactory.CreateUserManager(); // new AspNetSqlProviderService(m_Url);
            bool         authenticated = false;

            authenticated = userManager.Authenticate(m_ApplicationTextBox.Text, m_UserNameTextBox.Text, m_PasswordTextBox.Text);
            if (authenticated)
            {
                MessageBox.Show(this, "Successful Authentication", "Credentials Manager", MessageBoxButtons.OK);
            }
            else
            {
                MessageBox.Show(this, "Incorrect Credentials", "Credentials Manager", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }
Пример #22
0
        void OnUpdateUser(object sender, EventArgs e)
        {
            IMembershipManager membershipManager = UserManagerProviderFactory.CreateMembershipManager();// new AspNetSqlProviderService(m_Url);

            string[]           users  = membershipManager.GetAllUsers(m_Application);
            Predicate <string> exists = delegate(string user)
            {
                return(user == m_UserNameTextBox.Text);
            };

            if (Array.Exists(users, exists) == false)
            {
                m_Validator.SetError(m_UserNameTextBox, "User name does not exist");
                return;
            }
            m_Validator.Clear();

            if (m_EmailTextBox.Text == String.Empty)
            {
                m_Validator.SetError(m_EmailTextBox, "Email cannot be empty");
                return;
            }
            m_Validator.Clear();
            if (m_OldAnswerTextBox.Text == String.Empty && m_OldAnswerTextBox.Enabled)
            {
                m_Validator.SetError(m_OldAnswerTextBox, "Old answer cannot be empty");
                return;
            }
            m_Validator.Clear();
            if (m_NewQuestionTextBox.Text == String.Empty && m_NewQuestionTextBox.Enabled)
            {
                m_Validator.SetError(m_NewQuestionTextBox, "New question cannot be empty");
                return;
            }
            m_Validator.Clear();
            if (m_NewAnswerTextBox.Text == String.Empty && m_NewAnswerTextBox.Enabled)
            {
                m_Validator.SetError(m_NewAnswerTextBox, "New answer cannot be empty");
                return;
            }
            m_Validator.Clear();

            membershipManager.UpdateUser(m_Application, m_UserNameTextBox.Text, m_EmailTextBox.Text, m_OldAnswerTextBox.Text, m_NewQuestionTextBox.Text, m_NewAnswerTextBox.Text, m_ActiveUserCheckbox.Checked, m_LcokedOutCheckBox.Checked);

            Close();
        }
Пример #23
0
        void OnRemoveUsersFromAllRoles(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to remove the user " + UserToAssign + " from all its roles?", "Credentials Manager", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

            if (result == DialogResult.OK)
            {
                IRoleManager roleManager = UserManagerProviderFactory.CreateRoleManager(); // new AspNetSqlProviderService(ServiceAddress);
                string[]     roles       = roleManager.GetRolesForUser(ApplicationName, UserToAssign);
                if (roles.Length > 0)
                {
                    roleManager.RemoveUserFromRoles(ApplicationName, UserToAssign, roles);
                    RefreshRolesForUserComboBox();
                    RefreshUsersForRoleComboBox();
                    RefreshRolePageButtons();
                }
            }
        }
Пример #24
0
        void OnCheckedChanged(object sender, EventArgs e)
        {
            if (m_GeneratePasswordCheckBox.Checked)
            {
                IPasswordManager passwordManager = UserManagerProviderFactory.CreatePasswordManager(); // new AspNetSqlProviderService(m_Url);
                int    length          = passwordManager.GetMinRequiredPasswordLength(m_Application);
                int    nonAlphaNumeric = passwordManager.GetMinRequiredNonAlphanumericCharacters(m_Application);
                string password        = passwordManager.GeneratePassword(m_Application, length, nonAlphaNumeric);
                m_PasswordTextbox.Text          = password;
                m_ConfirmedPasswordTextBox.Text = password;

                m_PasswordTextbox.PasswordChar          = '\0';
                m_ConfirmedPasswordTextBox.PasswordChar = '\0';
            }
            else
            {
                m_PasswordTextbox.PasswordChar          = '*';
                m_ConfirmedPasswordTextBox.PasswordChar = '*';
            }
        }
Пример #25
0
        void OnDeleteAllUsers(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to delete all the users?", "Credentials Manager", MessageBoxButtons.OKCancel);

            if (result == DialogResult.OK)
            {
                IMembershipManager membershipManager = UserManagerProviderFactory.CreateMembershipManager(); // new AspNetSqlProviderService(ServiceAddress);
                membershipManager.DeleteAllUsers(ApplicationName, m_RelatedDataCheckBox.Checked);

                //Update the users page
                m_UsersListView.ClearItems();
                RefreshUserStatus();
                RefreshUsersPageButtonsAndMenuItems();

                //Upade the roles page
                RefreshUsersToAssignListView();
                RefreshUsersForRoleComboBox();
                RefreshRolesForUserComboBox();
                RefreshRolePageButtons();
            }
        }
Пример #26
0
        public UpdateUserDialog(string url, string application, string user)
        {
            InitializeComponent();

            m_Url                  = url;
            m_Application          = application;
            m_UserNameTextBox.Text = user;

            IMembershipManager membershipManager = UserManagerProviderFactory.CreateMembershipManager(); // new AspNetSqlProviderService(m_Url);
            UserInfo           info = membershipManager.GetUserInfo(m_Application, m_UserNameTextBox.Text);

            m_EmailTextBox.Text          = info.Email;
            m_ActiveUserCheckbox.Checked = info.IsApproved;
            m_LcokedOutCheckBox.Checked  = info.IsLockedOut;

            m_NewQuestionTextBox.Text = m_OldQuestionTextBox.Text = info.PasswordQuestion;

            IPasswordManager passwordManager = membershipManager as IPasswordManager;

            m_OldAnswerTextBox.Enabled   = passwordManager.EnablePasswordRetrieval(application);
            m_NewQuestionTextBox.Enabled = m_NewAnswerTextBox.Enabled = m_OldAnswerTextBox.Enabled;
        }
Пример #27
0
        void OnAssignUserToRole(object sender, EventArgs e)
        {
            IRoleManager roleManager = UserManagerProviderFactory.CreateRoleManager(); // new AspNetSqlProviderService(ServiceAddress);
            IUserManager userManager = roleManager as IUserManager;

            Debug.Assert(userManager != null);

            string role = m_RolesListView.CurrentListViewItem;

            Debug.Assert(role != String.Empty);

            if (userManager.IsInRole(ApplicationName, UserToAssign, role))
            {
                MessageBox.Show("The user " + UserToAssign + " is already a member of the role " + m_RolesListView.CurrentListViewItem, "Credentials Manager", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            else
            {
                roleManager.AddUserToRole(ApplicationName, UserToAssign, m_RolesListView.CurrentListViewItem);
                RefreshRolesForUserComboBox();
                RefreshUsersForRoleComboBox();
                RefreshRolePageButtons();
            }
        }
Пример #28
0
        void OnClosing(object sender, FormClosingEventArgs e)
        {
            if (ValidAddress)
            {
                IApplicationManager applicationManager       = UserManagerProviderFactory.CreateApplicationManager(); // new AspNetSqlProviderService(ServiceAddress);
                string[]            applicationsOnServer     = applicationManager.GetApplications();
                List <string>       applicationsOnServerList = new List <string>(applicationsOnServer);

                Predicate <string> contain = delegate(string str)
                {
                    return(applicationsOnServerList.Contains(str));
                };
                bool unsavedApps = !Array.TrueForAll(Applications, contain);
                if (unsavedApps)
                {
                    DialogResult result = MessageBox.Show("One or more applications have no users or roles defined. Closing the Credentials Manager application will delete those applications. Click OK to close or Cancel to continute using Credentials Manager.", "Credentials Manager", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                    if (result == DialogResult.Cancel)
                    {
                        e.Cancel = true;
                        return;
                    }
                }
            }
        }
Пример #29
0
        void OnCreateUser(object sender, EventArgs e)
        {
            IMembershipManager membershipManager = UserManagerProviderFactory.CreateMembershipManager(); // new AspNetSqlProviderService(m_Url);

            string[]           users  = membershipManager.GetAllUsers(m_Application);
            Predicate <string> exists = delegate(string user)
            {
                return(user == m_UserNameTextBox.Text);
            };

            if (Array.Exists(users, exists))
            {
                m_Validator.SetError(m_UserNameTextBox, "User name already exists");
                return;
            }
            m_Validator.Clear();

            if (m_PasswordTextbox.Text == String.Empty)
            {
                m_Validator.SetError(m_PasswordTextbox, "Password cannot be empty");
                return;
            }
            m_Validator.Clear();

            if (m_PasswordTextbox.Text != m_ConfirmedPasswordTextBox.Text)
            {
                m_Validator.SetError(m_ConfirmedPasswordTextBox, "Confirmed password does not match");
                return;
            }
            m_Validator.Clear();

            if (m_UserNameTextBox.Text == String.Empty)
            {
                m_Validator.SetError(m_UserNameTextBox, "User name cannot be empty");
                return;
            }
            m_Validator.Clear();

            if (m_EmailTextBox.Text == String.Empty)
            {
                m_Validator.SetError(m_EmailTextBox, "Email cannot be empty");
                return;
            }
            m_Validator.Clear();

            if (m_SecurityQuestionTextBox.Text == String.Empty)
            {
                m_Validator.SetError(m_SecurityQuestionTextBox, "Security question cannot be empty");
                return;
            }
            m_Validator.Clear();

            if (m_SecurityAnswerTextbox.Text == String.Empty)
            {
                m_Validator.SetError(m_SecurityAnswerTextbox, "Security question cannot be empty");
                return;
            }
            m_Validator.Clear();

            MembershipCreateStatus status = membershipManager.CreateUser(m_Application, m_UserNameTextBox.Text, m_PasswordTextbox.Text, m_EmailTextBox.Text, m_SecurityQuestionTextBox.Text, m_SecurityAnswerTextbox.Text, m_ActiveUserCheckBox.Checked);

            if (status != MembershipCreateStatus.Success)
            {
                MessageBox.Show(status.ToString(), "Credentials Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                m_Users.Add(m_UserNameTextBox.Text);
                m_CreatedUsersListView.AddItem(m_UserNameTextBox.Text, true);
                m_UserNameTextBox.Text = String.Empty;
                m_UserNameTextBox.Focus();
                m_GeneratePasswordCheckBox.Checked = false;
                m_PasswordTextbox.Text             = String.Empty;
                m_ConfirmedPasswordTextBox.Text    = String.Empty;
            }
        }