* returns the user id or false
*/
public static function checkPassword($uid, $password) {
- $user = self::getManager()->get($uid);
- if ($user) {
- if ($user->checkPassword($password)) {
- return $user->getUID();
- } else {
- return false;
- }
- } else {
- return false;
+ $manager = self::getManager();
+ $username = $manager->checkPassword($uid, $password);
+ if ($username !== false) {
+ return $manger->get($username);
}
+ return false;
}
/**
*/
public function login($uid, $password) {
$this->manager->emit('\OC\User', 'preLogin', array($uid, $password));
- $user = $this->manager->get($uid);
- if ($user) {
- $result = $user->checkPassword($password);
- if ($result and $user->isEnabled()) {
- $this->setUser($user);
- $this->manager->emit('\OC\User', 'postLogin', array($user, $password));
- return true;
- } else {
- return false;
+ $user = $this->manager->checkPassword($uid, $password);
+ if($user !== false) {
+ if (!is_null($user)) {
+ if ($user->isEnabled()) {
+ $this->setUser($user);
+ $this->manager->emit('\OC\User', 'postLogin', array($user, $password));
+ return true;
+ } else {
+ return false;
+ }
}
} else {
return false;
return !($result === false);
}
- /**
- * Check if the password is valid for the user
- *
- * @param $password
- * @return bool
- */
- public function checkPassword($password) {
- if ($this->backend->implementsActions(\OC_USER_BACKEND_CHECK_PASSWORD)) {
- $result = $this->backend->checkPassword($this->uid, $password);
- if ($result !== false) {
- $this->uid = $result;
- }
- return !($result === false);
- } else {
- return false;
- }
- }
-
/**
* Set the password of the user
*
$backend = $this->getMock('OC_User_Dummy');
$user = $this->getMock('\OC\User\User', array(), array('foo', $backend));
- $user->expects($this->once())
- ->method('checkPassword')
- ->with('bar')
- ->will($this->returnValue(true));
$user->expects($this->once())
->method('isEnabled')
->will($this->returnValue(true));
->will($this->returnValue('foo'));
$manager->expects($this->once())
- ->method('get')
- ->with('foo')
+ ->method('checkPassword')
+ ->with('foo', 'bar')
->will($this->returnValue($user));
$userSession = new \OC\User\Session($manager, $session);
$backend = $this->getMock('OC_User_Dummy');
$user = $this->getMock('\OC\User\User', array(), array('foo', $backend));
- $user->expects($this->once())
- ->method('checkPassword')
- ->with('bar')
- ->will($this->returnValue(true));
$user->expects($this->once())
->method('isEnabled')
->will($this->returnValue(false));
$manager->expects($this->once())
- ->method('get')
- ->with('foo')
+ ->method('checkPassword')
+ ->with('foo', 'bar')
->will($this->returnValue($user));
$userSession = new \OC\User\Session($manager, $session);
$backend = $this->getMock('OC_User_Dummy');
$user = $this->getMock('\OC\User\User', array(), array('foo', $backend));
- $user->expects($this->once())
- ->method('checkPassword')
- ->with('bar')
- ->will($this->returnValue(false));
$user->expects($this->never())
->method('isEnabled');
$manager->expects($this->once())
- ->method('get')
- ->with('foo')
- ->will($this->returnValue($user));
+ ->method('checkPassword')
+ ->with('foo', 'bar')
+ ->will($this->returnValue(false));
$userSession = new \OC\User\Session($manager, $session);
$userSession->login('foo', 'bar');
$backend = $this->getMock('OC_User_Dummy');
$manager->expects($this->once())
- ->method('get')
- ->with('foo')
- ->will($this->returnValue(null));
+ ->method('checkPassword')
+ ->with('foo', 'bar')
+ ->will($this->returnValue(false));
$userSession = new \OC\User\Session($manager, $session);
$userSession->login('foo', 'bar');