Issue#74 Case (in)sensitive login
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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 " .
|
||||
|
||||
@@ -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]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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")); ?>">
|
||||
|
||||
Reference in New Issue
Block a user