Exemplo n.º 1
0
        //Get All Users from the local database table
        public List <RemoteUser> getAllRemoteUsers()
        {
            this.connect();
            List <RemoteUser> usersList = new List <RemoteUser>();
            String            query     = "Select * from " + TABLE_NAME;
            SqlCeCommand      cmd       = new SqlCeCommand(query, this.conn);
            SqlCeDataReader   sqlReader = cmd.ExecuteReader();

            while (sqlReader.Read())
            {
                RemoteUser rUser = new RemoteUser();

                if (!DBNull.Value.Equals(sqlReader[0]))
                {
                    rUser.setID(sqlReader.GetInt32(0));
                }
                if (!DBNull.Value.Equals(sqlReader[1]))
                {
                    rUser.setSystemName(sqlReader.GetString(1));
                }
                if (!DBNull.Value.Equals(sqlReader[2]))
                {
                    rUser.setUsername(sqlReader.GetString(2));
                }
                if (!DBNull.Value.Equals(sqlReader[3]))
                {
                    rUser.setPassword(sqlReader.GetString(3));
                }
                if (!DBNull.Value.Equals(sqlReader[4]))
                {
                    rUser.setModifiedDate(sqlReader.GetDateTime(4));
                }
                if (!DBNull.Value.Equals(sqlReader[5]))
                {
                    rUser.setStatus(sqlReader.GetString(5));
                }

                usersList.Add(rUser);
            }
            this.disconnect();
            return(usersList);
        }
Exemplo n.º 2
0
        private void passwordWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // Password changing function that runs in background without disrupting the GUI
            int checkedCount        = computersCheckBox.CheckedItems.Count;
            int percentageInc       = (100 / computersCheckBox.CheckedItems.Count);
            int percentageCompleted = 0;

            bool allAdmins = allAdminsRadio.Checked;

            RemoteUserTableHandler rUserHandler = new RemoteUserTableHandler();

            for (int i = 0; i < checkedCount; i++)
            {
                List <String> userAccounts = new List <String>();

                String target = (String)computersCheckBox.CheckedItems[i];
                if (allAdmins)
                {
                    userAccounts = Utils.getRemoteAdmins(target);
                }
                else
                {
                    userAccounts.Add("Administrator");
                }

                foreach (String username in userAccounts)
                {
                    String          newPassword = this.passwordGenerate();
                    PasswordChanger rc          = new PasswordChanger(target);
                    RemoteUser      rUser       = new RemoteUser();
                    rUser.setSystemName(target);
                    rUser.setUsername(username);

                    if (rc.change(username, newPassword))
                    {//Successfully changed the password
                        rUser.setPassword(newPassword);
                        if (rUserHandler.exists(rUser))
                        {
                            rUserHandler.updatePassword(rUser);
                        }
                        else
                        {
                            rUserHandler.addUser(rUser);
                        }
                    }
                    else
                    {//Fails to chang the password
                        rUser.setStatus(rc.getError());
                        if (rUserHandler.exists(rUser))
                        {
                            rUserHandler.updateStatus(rUser);
                        }
                        else
                        {
                            rUserHandler.addUser(rUser);
                        }
                    }
                }

                percentageCompleted = ((i + 1) * percentageInc);
                passwordWorker.ReportProgress(percentageCompleted);

                if (passwordWorker.CancellationPending)
                {
                    e.Cancel = true;
                    passwordWorker.ReportProgress(0);
                    return;
                }

                Thread.Sleep(100);
            }

            passwordWorker.ReportProgress(100);
        }
        //Get All Users from the local database table
        public List<RemoteUser> getAllRemoteUsers()
        {
            this.connect();
            List<RemoteUser> usersList = new List<RemoteUser>();
            String query = "Select * from " + TABLE_NAME;
            SqlCeCommand cmd = new SqlCeCommand(query,this.conn);
            SqlCeDataReader sqlReader = cmd.ExecuteReader();

            while(sqlReader.Read())
            {
                RemoteUser rUser = new RemoteUser();

                if (!DBNull.Value.Equals(sqlReader[0]))
                    rUser.setID(sqlReader.GetInt32(0));
                if (!DBNull.Value.Equals(sqlReader[1]))
                    rUser.setSystemName(sqlReader.GetString(1));
                if (!DBNull.Value.Equals(sqlReader[2]))
                    rUser.setUsername(sqlReader.GetString(2));
                if (!DBNull.Value.Equals(sqlReader[3]))
                    rUser.setPassword(sqlReader.GetString(3));
                if(! DBNull.Value.Equals(sqlReader[4]))
                    rUser.setModifiedDate(sqlReader.GetDateTime(4));
                if (!DBNull.Value.Equals(sqlReader[5]))
                    rUser.setStatus(sqlReader.GetString(5));

                usersList.Add(rUser);
            }
            this.disconnect();
            return usersList;
        }