diff options
author | Marcin Łojewski <marcin.lojewski@mlojewski.me> | 2018-10-28 19:40:12 +0300 |
---|---|---|
committer | Marcin Łojewski <marcin.lojewski@mlojewski.me> | 2018-10-28 20:19:58 +0300 |
commit | 09050966128380e7d429325c241c1ef95b0eb756 (patch) | |
tree | cde8f865d6d64b72cecca0c1161cffb53366f5fc | |
parent | 9ab6df0f7699b8b5148bee10fa982b20f64eb9c3 (diff) |
Issue#74 Case (in)sensitive login
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | lib/Backend/UserBackend.php | 6 | ||||
-rw-r--r-- | lib/Constant/Opt.php | 1 | ||||
-rw-r--r-- | lib/Constant/Query.php | 1 | ||||
-rw-r--r-- | lib/Query/QueryProvider.php | 5 | ||||
-rw-r--r-- | lib/Repository/UserRepository.php | 20 | ||||
-rw-r--r-- | templates/admin.php | 3 |
8 files changed, 29 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index ebbb5d9..5bf7521 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Whirlpool hash algorithm - 'Prepend salt' toggle - Drupal 7 hash algorithm +- Case-insensitive username option ### Fixed - Error when 'Display name' not set - Encoding of iteration for 'Extended DES (Crypt)' @@ -49,6 +49,7 @@ Name | Description | Details --- | --- | --- **Allow display name change** | With this option enabled user can change its display name. The display name change is propagated to the database. | Optional.<br/>Default: false.<br/>Requires: user *Display name* column. **Allow password change** | Can user change its password. The password change is propagated to the database. See [Hash algorithms](#hash-algorithms). | Optional.<br/>Default: false. +**Case-insensitive username** | Whether user query should be case-sensitive or case-insensitive. | Optional.<br/>Default: false. **Use cache** | Use database query results cache. The cache can be cleared any time with the *Clear cache* button click. | Optional.<br/>Default: false. **Hash algorithm** | How users passwords are stored in the database. See [Hash algorithms](#hash-algorithms). | Mandatory. **Email sync** | Sync e-mail address with the Nextcloud.<br/>- *None* - Disables this feature. This is the default option.<br/>- *Synchronise only once* - Copy the e-mail address to the Nextcloud preferences if its not set.<br/>- *Nextcloud always wins* - Always copy the e-mail address to the database. This updates the user table.<br/>- *SQL always wins* - Always copy the e-mail address to the Nextcloud preferences. | Optional.<br/>Default: *None*.<br/>Requires: user *Email* column. diff --git a/lib/Backend/UserBackend.php b/lib/Backend/UserBackend.php index a5d3b3a..e26f708 100644 --- a/lib/Backend/UserBackend.php +++ b/lib/Backend/UserBackend.php @@ -292,11 +292,13 @@ final class UserBackend extends ABackend implements return false; } - $user = $this->userRepository->findByUid($uid); - if (!($user instanceof User)) { + $caseSensitive = empty($this->properties[Opt::CASE_INSENSITIVE_USERNAME]); + $user = $this->userRepository->findByUid($uid, $caseSensitive); + if (!($user instanceof User) || ($caseSensitive && $user->uid !== $uid)) { return false; } + $uid = $user->uid; $password = $this->addSalt($user, $password); $isCorrect = $passwordAlgorithm->checkPassword( diff --git a/lib/Constant/Opt.php b/lib/Constant/Opt.php index fe6449a..75b0da6 100644 --- a/lib/Constant/Opt.php +++ b/lib/Constant/Opt.php @@ -28,6 +28,7 @@ namespace OCA\UserSQL\Constant; */ final class Opt { + const CASE_INSENSITIVE_USERNAME = "opt.case_insensitive_username"; const CRYPTO_CLASS = "opt.crypto_class"; const EMAIL_SYNC = "opt.email_sync"; const HOME_LOCATION = "opt.home_location"; diff --git a/lib/Constant/Query.php b/lib/Constant/Query.php index 35eceb7..8cbff2c 100644 --- a/lib/Constant/Query.php +++ b/lib/Constant/Query.php @@ -35,6 +35,7 @@ final class Query const FIND_GROUP_USERS = "find_group_users"; const FIND_GROUPS = "find_groups"; const FIND_USER = "find_user"; + const FIND_USER_CASE_INSENSITIVE = "find_user_case_insensitive"; const FIND_USER_GROUPS = "find_user_groups"; const FIND_USERS = "find_users"; const UPDATE_DISPLAY_NAME = "update_display_name"; diff --git a/lib/Query/QueryProvider.php b/lib/Query/QueryProvider.php index 06cd02b..cd027d0 100644 --- a/lib/Query/QueryProvider.php +++ b/lib/Query/QueryProvider.php @@ -144,6 +144,11 @@ class QueryProvider implements \ArrayAccess "FROM $user " . "WHERE $uUID = :$uidParam", + Query::FIND_USER_CASE_INSENSITIVE => + "SELECT $userColumns, $uPassword AS password " . + "FROM $user " . + "WHERE lower($uUID) = lower(:$uidParam)", + Query::FIND_USER_GROUPS => "SELECT $groupColumns " . "FROM $group, $userGroup " . diff --git a/lib/Repository/UserRepository.php b/lib/Repository/UserRepository.php index 91438ea..9841cf0 100644 --- a/lib/Repository/UserRepository.php +++ b/lib/Repository/UserRepository.php @@ -53,18 +53,26 @@ class UserRepository } /** - * Get a user entity object. + * Get an user entity object. * - * @param string $uid The user ID. + * @param string $uid The user ID. + * @param bool $caseSensitive TRUE for case sensitive search, + * FALSE for case insensitive search. * * @return User The user entity, NULL if it does not exists or * FALSE on failure. */ - public function findByUid($uid) + public function findByUid($uid, $caseSensitive = true) { - return $this->dataQuery->queryEntity( - Query::FIND_USER, User::class, [Query::UID_PARAM => $uid] - ); + if ($caseSensitive) { + return $this->dataQuery->queryEntity( + Query::FIND_USER, User::class, [Query::UID_PARAM => $uid] + ); + } else { + return $this->dataQuery->queryEntity( + Query::FIND_USER_CASE_INSENSITIVE, User::class, [Query::UID_PARAM => $uid] + ); + } } /** diff --git a/templates/admin.php b/templates/admin.php index 64c4301..b722b8b 100644 --- a/templates/admin.php +++ b/templates/admin.php @@ -109,7 +109,8 @@ function print_select_options( <p class="settings-hint"><?php p($l->t("Here are all currently supported options.")); ?></p> <fieldset><?php print_checkbox_input($l, "opt-name_change", "Allow display name change", $_["opt.name_change"]); - print_checkbox_input($l, "opt-password_change", "Allow password change", $_["opt.password_change"]); ?> + print_checkbox_input($l, "opt-password_change", "Allow password change", $_["opt.password_change"]); + print_checkbox_input($l, "opt-case_insensitive_username", "Case-insensitive username", $_["opt.case_insensitive_username"]); ?> <div class="button-right"><?php print_checkbox_input($l, "opt-use_cache", "Use cache", $_["opt.use_cache"], false); ?> <input type="submit" id="user_sql-clear_cache" value="<?php p($l->t("Clear cache")); ?>"> |