Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/private/User/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,15 @@ public function completeLogin(IUser $user, array $loginDetails, $regenerateSessi
throw new LoginException($message);
}

/**
* Removes domain prefix from username, if any, for defined domain names
* @param string $user
* @return string
*/
private function stripDomainName($user) {
return preg_replace("/^(?:(?:NC|NEXTCLOUD|WORKGROUP)\\\)?(.*)/", "\${1}", $user);
}

/**
* Tries to log in a client
*
Expand Down Expand Up @@ -447,7 +456,7 @@ public function logClientIn($user,
}

// Try to login with this username and password
if (!$this->login($user, $password)) {
if (!$this->login($user, $password) && !$this->login($this->stripDomainName($user), $password)) {
// Failed, maybe the user used their email address
if (!filter_var($user, FILTER_VALIDATE_EMAIL)) {
return false;
Expand Down Expand Up @@ -779,7 +788,7 @@ private function validateToken($token, $user = null) {
}

// Check if login names match
if (!is_null($user) && $dbToken->getLoginName() !== $user) {
if (!is_null($user) && $dbToken->getLoginName() !== $user && $dbToken->getLoginName() !== $this->stripDomainName($user)) {
// TODO: this makes it impossible to use different login names on browser and client
// e.g. login by e-mail 'user@example.com' on browser for generating the token will not
// allow to use the client token with the login name 'user'.
Expand Down