forked from owncloud/music
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ampache/Subsonic: Case-insensitive user name checking
In the normal log-in of ownCloud and Nextcloud, the user names are allowed using any casing. The same is true at least for Ampache proper. Now also the APIs of the Music app follow the suite. refs owncloud#1147
- Loading branch information
Showing
4 changed files
with
30 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* @author Morris Jobke <[email protected]> | ||
* @author Pauli Järvinen <[email protected]> | ||
* @copyright Morris Jobke 2013, 2014 | ||
* @copyright Pauli Järvinen 2018 - 2023 | ||
* @copyright Pauli Järvinen 2018 - 2024 | ||
*/ | ||
|
||
namespace OCA\Music\Db; | ||
|
@@ -58,6 +58,23 @@ public function getPasswordHash(int $id) : ?string { | |
return $row['hash']; | ||
} | ||
|
||
/** | ||
* @param string $user Username, case-insensitive | ||
* @return ?string Case-sensitively correct username, if the user has any API key(s) | ||
*/ | ||
public function getProperUserId(string $user) : ?string { | ||
$sql = 'SELECT `user_id` FROM `*PREFIX*music_ampache_users` WHERE LOWER(`user_id`) = LOWER(?)'; | ||
$params = [$user]; | ||
$result = $this->db->executeQuery($sql, $params); | ||
$row = $result->fetch(); | ||
|
||
if ($row === false) { | ||
return null; | ||
} | ||
|
||
return $row['user_id']; | ||
} | ||
|
||
public function getUserId(int $id) : ?string { | ||
$sql = 'SELECT `user_id` FROM `*PREFIX*music_ampache_users` WHERE `id` = ?'; | ||
$params = [$id]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
* later. See the COPYING file. | ||
* | ||
* @author Pauli Järvinen <[email protected]> | ||
* @copyright Pauli Järvinen 2019, 2020 | ||
* @copyright Pauli Järvinen 2019 - 2024 | ||
*/ | ||
|
||
namespace OCA\Music\Middleware; | ||
|
@@ -103,7 +103,8 @@ private function checkAuthentication(SubsonicController $controller) { | |
$pass = \hex2bin(\substr($pass, \strlen('enc:'))); | ||
} | ||
|
||
if ($this->credentialsAreValid($user, $pass)) { | ||
$user = $this->userMapper->getProperUserId($user); | ||
if ($user !== null && $this->credentialsAreValid($user, $pass)) { | ||
$controller->setAuthenticatedUser($user); | ||
} else { | ||
throw new SubsonicException('Invalid Login', 40); | ||
|