Piwik\Plugins\UsersManager\API::getTokenAuth PHP Метод

getTokenAuth() публичный Метод

If the username/password combination is incorrect an invalid token will be returned.
public getTokenAuth ( string $userLogin, string $md5Password ) : string
$userLogin string Login
$md5Password string hashed string of the password (using current hash function; MD5-named for historical reasons)
Результат string
    public function getTokenAuth($userLogin, $md5Password)
    {
        UsersManager::checkPasswordHash($md5Password, Piwik::translate('UsersManager_ExceptionPasswordMD5HashExpected'));
        $user = $this->model->getUser($userLogin);
        if (!$this->password->verify($md5Password, $user['password'])) {
            return md5($userLogin . microtime(true) . Common::generateUniqId());
        }
        if ($this->password->needsRehash($user['password'])) {
            $this->updateUser($userLogin, $this->password->hash($md5Password));
        }
        return $user['token_auth'];
    }

Usage Example

Пример #1
0
 private function _checkUserHasNotChanged($user, $newPassword, $newEmail = null, $newAlias = null)
 {
     if (is_null($newEmail)) {
         $newEmail = $user['email'];
     }
     if (is_null($newAlias)) {
         $newAlias = $user['alias'];
     }
     $userAfter = $this->api->getUser($user["login"]);
     unset($userAfter['date_registered']);
     // we now compute what the token auth should be, it should always be a hash of the login and the current password
     // if the password has changed then the token_auth has changed!
     $user['token_auth'] = $this->api->getTokenAuth($user["login"], md5($newPassword));
     $user['password'] = md5($newPassword);
     $user['email'] = $newEmail;
     $user['alias'] = $newAlias;
     $user['superuser_access'] = 0;
     $this->assertEquals($user, $userAfter);
 }
All Usage Examples Of Piwik\Plugins\UsersManager\API::getTokenAuth