123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- use ChamiloSession as Session;
- $wsUrl = '';
- require_once dirname(__FILE__) . '/functions.inc.php';
- $isValid = loginWSAuthenticate($login, $password, $wsUrl);
- if ($isValid === 1) {
-
- $chamiloUser = UserManager::get_user_info($login);
- $loginFailed = false;
- $_user['user_id'] = $chamiloUser['user_id'];
- $_user['status'] = (isset($chamiloUser['status']) ? $chamiloUser['status'] : 5);
- $_user['uidReset'] = true;
- Session::write('_user', $_user);
- $uidReset = true;
- $logging_in = true;
- Event::event_login($_user['user_id']);
- } else {
-
- $loginFailed = true;
- $uidReset = false;
- if (isset($_user) && isset($_user['user_id'])) {
- unset($_user['user_id']);
- }
- }
- function loginWSAuthenticate($username, $password, $wsUrl) {
-
- if (empty($username) or empty($password) or empty($wsUrl)) {
- return false;
- }
-
- $client = new SoapClient($wsUrl);
- if (!$client) {
- return false;
- }
-
- include_once api_get_path(LIBRARY_PATH).'phpseclib/Crypt/AES.php';
-
- $key = '-+*%$({[]})$%*+-';
-
- $blockSize = 16;
- $padding = $blockSize - (strlen($password)%$blockSize);
- $password .= str_repeat(chr($padding),$padding);
- $cipher = new Crypt_AES(CRYPT_AES_MODE_CFB);
- $cipher->setKeyLength(128);
- $cipher->setKey($key);
- $cipher->setIV($key);
- $cipheredPass = $cipher->encrypt($password);
-
-
-
-
-
- $passCrypted = base64_encode($cipheredPass);
-
- try {
- $response = $client->validateUser(array('user' => $username, 'pass' => $passCrypted, 'system' => 'chamilo'));
- } catch (SoapFault $fault) {
- error_log('Caught something');
- if ($fault->faultstring != 'Could not connect to host') {
- error_log('Not a connection problem');
- throw $fault;
- } else {
- error_log('Could not connect to WS host');
- }
- return 0;
- }
- return $response->validateUserResult;
- }
|