diff --git a/lib/private/legacy/preferences.php b/lib/private/legacy/preferences.php
index 4f88b60f245279139c6c0f7745603ca099da8337..4b68b0e69aa453021bc4ec4169f2fd47bb44c381 100644
--- a/lib/private/legacy/preferences.php
+++ b/lib/private/legacy/preferences.php
@@ -28,6 +28,28 @@ OC_Preferences::$object = new \OC\Preferences(OC_DB::getConnection());
  */
 class OC_Preferences{
 	public static $object;
+	/**
+	 * Get all users using the preferences
+	 * @return array an array of user ids
+	 *
+	 * This function returns a list of all users that have at least one entry
+	 * in the preferences table.
+	 */
+	public static function getUsers() {
+		return self::$object->getUsers();
+	}
+
+	/**
+	 * Get all apps of a user
+	 * @param string $user user
+	 * @return integer[] with app ids
+	 *
+	 * This function returns a list of all apps of the user that have at least
+	 * one entry in the preferences table.
+	 */
+	public static function getApps( $user ) {
+		return self::$object->getApps( $user );
+	}
 
 	/**
 	 * Get the available keys for an app
diff --git a/lib/private/preferences.php b/lib/private/preferences.php
index 58f7541949703db6380cf9762d276e05f6b4ec86..cdaa207449d8b2b186190d7cbbcc8190d8702c48 100644
--- a/lib/private/preferences.php
+++ b/lib/private/preferences.php
@@ -67,6 +67,25 @@ class Preferences {
 		$this->conn = $conn;
 	}
 
+	/**
+	 * Get all users using the preferences
+	 * @return array an array of user ids
+	 *
+	 * This function returns a list of all users that have at least one entry
+	 * in the preferences table.
+	 */
+	public function getUsers() {
+		$query = 'SELECT DISTINCT `userid` FROM `*PREFIX*preferences`';
+		$result = $this->conn->executeQuery($query);
+
+		$users = array();
+		while ($userid = $result->fetchColumn()) {
+			$users[] = $userid;
+		}
+
+		return $users;
+	}
+
 	/**
 	 * @param string $user
 	 * @return array[]
@@ -89,6 +108,19 @@ class Preferences {
 		return $data;
 	}
 
+	/**
+	 * Get all apps of an user
+	 * @param string $user user
+	 * @return integer[] with app ids
+	 *
+	 * This function returns a list of all apps of the user that have at least
+	 * one entry in the preferences table.
+	 */
+	public function getApps($user) {
+		$data = $this->getUserValues($user);
+		return array_keys($data);
+	}
+
 	/**
 	 * Get the available keys for an app
 	 * @param string $user user
diff --git a/tests/lib/preferences-singleton.php b/tests/lib/preferences-singleton.php
index 2bea889da9b3adccfc7170c18baa80cdb899412d..01e15acdfe109d52492670eb889a83baef937557 100644
--- a/tests/lib/preferences-singleton.php
+++ b/tests/lib/preferences-singleton.php
@@ -40,6 +40,34 @@ class Test_Preferences extends \Test\TestCase {
 		parent::tearDownAfterClass();
 	}
 
+	public function testGetUsers() {
+		$query = \OC_DB::prepare('SELECT DISTINCT `userid` FROM `*PREFIX*preferences`');
+		$result = $query->execute();
+		$expected = array();
+		while ($row = $result->fetchRow()) {
+			$expected[] = $row['userid'];
+		}
+
+		sort($expected);
+		$users = \OC_Preferences::getUsers();
+		sort($users);
+		$this->assertEquals($expected, $users);
+	}
+
+	public function testGetApps() {
+		$query = \OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*preferences` WHERE `userid` = ?');
+		$result = $query->execute(array('Someuser'));
+		$expected = array();
+		while ($row = $result->fetchRow()) {
+			$expected[] = $row['appid'];
+		}
+
+		sort($expected);
+		$apps = \OC_Preferences::getApps('Someuser');
+		sort($apps);
+		$this->assertEquals($expected, $apps);
+	}
+
 	public function testGetKeys() {
 		$query = \OC_DB::prepare('SELECT DISTINCT `configkey` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ?');
 		$result = $query->execute(array('Someuser', 'getkeysapp'));