예제 #1
0
        private void NewUser()
        {
            UserDialogue userDialog = new UserDialogue();

            userDialog.Text                 = "New User";
            userDialog.userTextBox.Text     = "";
            userDialog.userTextBox.Enabled  = true;
            userDialog.passwordTextBox.Text = "";
            userDialog.ShowDialog();
            if (userDialog.DialogResult == DialogResult.OK)
            {
                if (userDialog.userTextBox.Text != "")
                {
                    bool add = true;
                    foreach (User u in userList.Items)
                    {
                        if (userDialog.userTextBox.Text == u.Username)
                        {
                            MessageBox.Show("Username: \"" + u.Username + "\" already taken.");
                            add = false;
                            break;
                        }
                    }
                    if (add)
                    {
                        User u2 = new User(userDialog.userTextBox.Text);
                        if (ServerOptions.UseStrongPasswords)
                        {
                            if (Authenticator.IsStrongPassword(u2, userDialog.passwordTextBox.Text))
                            {
                                u2.Password = PasswordHashUtility.HashPassword(userDialog.passwordTextBox.Text);

                                userList.Items.Add(u2);
                            }
                            else
                            {
                                MessageBox.Show(passwordRulesString);
                            }
                        }
                        else
                        {
                            u2.Password = PasswordHashUtility.HashPassword(userDialog.passwordTextBox.Text);

                            userList.Items.Add(u2);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Invalid Username");
                }
            }
            SetButtons();
        }
예제 #2
0
        public void AuthenticationRequest(string username, string password, string terminal_id)
        {
            _AuthenticationRequest = SimulationEventFactory.BuildEvent(ref _SimModel, "AuthenticationRequest");
            ((StringValue)(_AuthenticationRequest["Username"])).value   = username;
            ((StringValue)(_AuthenticationRequest["Password"])).value   = PasswordHashUtility.HashPassword(password);
            ((StringValue)(_AuthenticationRequest["TerminalID"])).value = terminal_id;

            if (DDD_Global.Instance.IsConnected)
            {
                DDD_Global.Instance.PutEvent(_AuthenticationRequest);
            }
        }
예제 #3
0
        private void EditUser()
        {
            User selected = (User)userList.SelectedItem;

            UserDialogue userDialog = new UserDialogue();

            userDialog.Text                = "Edit User";
            userDialog.userTextBox.Text    = selected.Username;
            userDialog.userTextBox.Enabled = false;
            string oldPassword = selected.Password;

            userDialog.passwordTextBox.Text = oldPassword;
            userDialog.ShowDialog();

            if (userDialog.DialogResult == DialogResult.OK)
            {
                if (userDialog.passwordTextBox.Text == oldPassword)
                {
                    // do nothing
                }
                else if (ServerOptions.UseStrongPasswords)
                {
                    if (Authenticator.IsStrongPassword(selected, userDialog.passwordTextBox.Text))
                    {
                        selected.Password = PasswordHashUtility.HashPassword(userDialog.passwordTextBox.Text);
                    }
                    else
                    {
                        MessageBox.Show(passwordRulesString);
                    }
                }
                else
                {
                    selected.Password = PasswordHashUtility.HashPassword(userDialog.passwordTextBox.Text);
                }
            }
            SetButtons();
            //ud.Show();
        }
예제 #4
0
        public static bool IsStrongPassword(User user, string password)
        {
            // 2+ punctuation
            Regex           punctuationRegex2 = new Regex(@"\p{P}");
            MatchCollection c;

            c = punctuationRegex2.Matches(password);
            if (c.Count < 2)
            {
                return(false);
            }

            // Minimum of 10 characters
            if (password.Length < 10)
            {
                return(false);
            }

            // 2+ numbers
            Regex numbersRegex = new Regex(@"[0-9]");

            c = numbersRegex.Matches(password);
            if (c.Count < 2)
            {
                return(false);
            }

            // 2+ uppercase letters
            Regex uppercaseRegex = new Regex(@"[A-Z]");

            c = uppercaseRegex.Matches(password);
            if (c.Count < 2)
            {
                return(false);
            }

            // 2+ lowercase letters
            Regex lowercaseRegex = new Regex(@"[a-z]");

            c = lowercaseRegex.Matches(password);
            if (c.Count < 2)
            {
                return(false);
            }

            // 2+ punctuation
            Regex punctuationRegex = new Regex(@"\p{P}");

            c = punctuationRegex.Matches(password);
            if (c.Count < 2)
            {
                return(false);
            }

            // Cannot re-use the last 10 passwords
            if (user.passwords.Contains(PasswordHashUtility.HashPassword(password)))
            {
                return(false);
            }



            return(true);
        }