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