diff --git a/core/modules/user/lib/Drupal/user/Plugin/Block/UserNewBlock.php b/core/modules/user/lib/Drupal/user/Plugin/Block/UserNewBlock.php
index 01209c5..3c3c445 100644
--- a/core/modules/user/lib/Drupal/user/Plugin/Block/UserNewBlock.php
+++ b/core/modules/user/lib/Drupal/user/Plugin/Block/UserNewBlock.php
@@ -65,7 +65,13 @@ public function blockSubmit($form, &$form_state) {
    */
   public function build() {
     // Retrieve a list of new users who have accessed the site successfully.
-    $uids = db_query_range('SELECT uid FROM {users} WHERE status <> 0 AND access <> 0 ORDER BY created DESC', 0, $this->configuration['whois_new_count'])->fetchCol();
+    $uids = \Drupal::entityQuery('user')
+      ->condition('status', 0, '<>')
+      ->condition('access', 0, '<>')
+      ->sort('created', 'DESC')
+      ->range(0, $this->configuration['whois_new_count'])
+      ->execute();
+
     $build = array(
       '#theme' => 'item_list__user__new',
       '#items' => array(),
diff --git a/core/modules/user/lib/Drupal/user/Plugin/Block/UserOnlineBlock.php b/core/modules/user/lib/Drupal/user/Plugin/Block/UserOnlineBlock.php
index 1b1e506..5a31ab5 100644
--- a/core/modules/user/lib/Drupal/user/Plugin/Block/UserOnlineBlock.php
+++ b/core/modules/user/lib/Drupal/user/Plugin/Block/UserOnlineBlock.php
@@ -82,7 +82,10 @@ public function build() {
     $interval = REQUEST_TIME - $this->configuration['seconds_online'];
 
     // Perform database queries to gather online user lists.
-    $authenticated_count = db_query("SELECT COUNT(uid) FROM {users} WHERE access >= :timestamp", array(':timestamp' => $interval))->fetchField();
+    $authenticated_count = \Drupal::entityQuery('user')
+      ->condition('access', $interval, '>=')
+      ->count()
+      ->execute();
 
     $build = array(
       '#theme' => 'item_list__user__online',
@@ -92,7 +95,13 @@ public function build() {
     // Display a list of currently online users.
     $max_users = $this->configuration['max_list_count'];
     if ($authenticated_count && $max_users) {
-      $uids = db_query_range('SELECT uid FROM {users} WHERE access >= :interval AND uid > 0 ORDER BY access DESC', 0, $max_users, array(':interval' => $interval))->fetchCol();
+      $uids = \Drupal::entityQuery('user')
+        ->condition('access', $interval, '>=')
+        ->condition('uid', 0, '>')
+        ->sort('access', 'DESC')
+        ->range(0, $max_users)
+        ->execute();
+
       foreach (user_load_multiple($uids) as $account) {
         $username = array(
           '#theme' => 'username',
diff --git a/core/modules/user/lib/Drupal/user/UserAutocomplete.php b/core/modules/user/lib/Drupal/user/UserAutocomplete.php
index 4d36923..f5ebd7b 100644
--- a/core/modules/user/lib/Drupal/user/UserAutocomplete.php
+++ b/core/modules/user/lib/Drupal/user/UserAutocomplete.php
@@ -65,9 +65,15 @@ public function getMatches($string, $include_anonymous = FALSE) {
           $matches[$anonymous_name] = check_plain($anonymous_name);
         }
       }
-      $result = $this->connection->select('users')->fields('users', array('name'))->condition('name', db_like($string) . '%', 'LIKE')->range(0, 10)->execute();
-      foreach ($result as $account) {
-        $matches[$account->name] = check_plain($account->name);
+
+      $uids = \Drupal::entityQuery('user')
+        ->condition('name', db_like($string) . '%', 'LIKE')
+        ->range(0, 10)
+        ->execute();
+
+      $controller = \Drupal::entityManager()->getStorageController('user');
+      foreach ($controller->loadMultiple($uids) as $account) {
+        $matches[$account->getUsername()] = check_plain($account->getUsername());
       }
     }
 
diff --git a/core/modules/user/user.admin.inc b/core/modules/user/user.admin.inc
index 4caec43..42bb22a 100644
--- a/core/modules/user/user.admin.inc
+++ b/core/modules/user/user.admin.inc
@@ -10,30 +10,19 @@
  */
 function user_admin_account() {
   $header = array(
-    'username' => array('data' => t('Username'), 'field' => 'u.name'),
-    'status' => array('data' => t('Status'), 'field' => 'u.status', 'class' => array(RESPONSIVE_PRIORITY_LOW)),
+    'username' => array('data' => t('Username'), 'specifier' => 'username'),
+    'status' => array('data' => t('Status'), 'specifier' => 'status', 'class' => array(RESPONSIVE_PRIORITY_LOW)),
     'roles' => array('data' => t('Roles'), 'class' => array(RESPONSIVE_PRIORITY_LOW)),
-    'member_for' => array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc', 'class' => array(RESPONSIVE_PRIORITY_LOW)),
-    'access' => array('data' => t('Last access'), 'field' => 'u.access', 'class' => array(RESPONSIVE_PRIORITY_LOW)),
+    'member_for' => array('data' => t('Member for'), 'specifier' => 'created', 'sort' => 'desc', 'class' => array(RESPONSIVE_PRIORITY_LOW)),
+    'access' => array('data' => t('Last access'), 'specifier' => 'access', 'class' => array(RESPONSIVE_PRIORITY_LOW)),
     'operations' => t('Operations'),
   );
 
-  $query = db_select('users', 'u');
-  $query->condition('u.uid', 0, '<>');
-
-  $count_query = clone $query;
-  $count_query->addExpression('COUNT(u.uid)');
-
-  $query = $query
-    ->extend('Drupal\Core\Database\Query\PagerSelectExtender')
-    ->extend('Drupal\Core\Database\Query\TableSortExtender');
-  $query
-    ->fields('u', array('uid'))
-    ->limit(50)
-    ->orderByHeader($header)
-    ->setCountQuery($count_query);
-  $uids = $query->execute()
-    ->fetchCol('uid');
+  $uids = Drupal::entityQuery('user')
+    ->condition('uid', 0, '<>')
+    ->tableSort($header)
+    ->pager(50)
+    ->execute();
 
   $destination = drupal_get_destination();
   $accounts = user_load_multiple($uids);
diff --git a/core/modules/user/user.module b/core/modules/user/user.module
index 91e7ee1..2705381 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -463,11 +463,10 @@ function user_access($string, AccountInterface $account = NULL) {
  *   FALSE if the user is not blocked.
  */
 function user_is_blocked($name) {
-  return db_select('users')
-    ->fields('users', array('name'))
+  return Drupal::entityQuery('user')
     ->condition('name', db_like($name), 'LIKE')
     ->condition('status', 0)
-    ->execute()->fetchObject();
+    ->execute();
 }
 
 /**
@@ -522,16 +521,14 @@ function user_search_access() {
 function user_search_execute($keys = NULL, $conditions = NULL) {
   // Replace wildcards with MySQL/PostgreSQL wildcards.
   $keys = preg_replace('!\*+!', '%', $keys);
-  $query = db_select('users')
-    ->extend('Drupal\Core\Database\Query\PagerSelectExtender');
-  $query->fields('users', array('uid'));
+  $query = Drupal::entityQuery('user');
   if (user_access('administer users')) {
     // Administrators can also search in the otherwise private email field, and
     // they don't need to be restricted to only active users.
-    $query->fields('users', array('mail'));
-    $query->condition(db_or()->
-      condition('name', '%' . db_like($keys) . '%', 'LIKE')->
-      condition('mail', '%' . db_like($keys) . '%', 'LIKE'));
+    $group = $query->orConditionGroup()
+      ->condition('name', '%' . db_like($keys) . '%', 'LIKE')
+      ->condition('mail', '%' . db_like($keys) . '%', 'LIKE');
+    $query->condition($group);
   }
   else {
     // Regular users can only search via usernames, and we do not show them
@@ -540,9 +537,8 @@ function user_search_execute($keys = NULL, $conditions = NULL) {
       ->condition('status', 1);
   }
   $uids = $query
-    ->limit(15)
-    ->execute()
-    ->fetchCol();
+    ->pager(15)
+    ->execute();
   $accounts = user_load_multiple($uids);
 
   $results = array();
@@ -1137,10 +1133,7 @@ function user_login_finalize(UserInterface $account) {
   // Update the user table timestamp noting user has logged in.
   // This is also used to invalidate one-time login links.
   $account->setLastLoginTime(REQUEST_TIME);
-  db_update('users')
-    ->fields(array('login' => $user->getLastLoginTime()))
-    ->condition('uid', $user->id())
-    ->execute();
+  $controller = Drupal::entityManager()->getStorageController('user')->save($user);
 
   // Regenerate the session ID to prevent against session fixation attacks.
   // This is called before hook_user in case one of those functions fails
@@ -1969,12 +1962,10 @@ function user_node_load($nodes, $types) {
     $uids[$nid] = $node->getAuthorId();
   }
 
-  // Fetch name and data for these users.
-  $user_names = db_query("SELECT uid, name FROM {users} WHERE uid IN (:uids)", array(':uids' => $uids))->fetchAllKeyed();
-
-  // Add these values back into the node objects.
-  foreach ($uids as $nid => $uid) {
-    $nodes[$nid]->name = $user_names[$uid];
+  // Add loaded user name values back into the node objects.
+  $controller = Drupal::entityManager()->getStorageController('user');
+  foreach ($controller->loadMultiple($uids) as $user) {
+    $nodes[$user->id()]->name = $user->getUsername();
   }
 }
 
