當前位置: 首頁>>代碼示例>>PHP>>正文


PHP OC_Util::generateRandomBytes方法代碼示例

本文整理匯總了PHP中OC_Util::generateRandomBytes方法的典型用法代碼示例。如果您正苦於以下問題:PHP OC_Util::generateRandomBytes方法的具體用法?PHP OC_Util::generateRandomBytes怎麽用?PHP OC_Util::generateRandomBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在OC_Util的用法示例。


在下文中一共展示了OC_Util::generateRandomBytes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: addSecret

 /**
  * Adds a secret to config.php
  */
 private function addSecret()
 {
     if (\OC::$server->getConfig()->getSystemValue('secret', null) === null) {
         $secret = \OC_Util::generateRandomBytes(96);
         \OC::$server->getConfig()->setSystemValue('secret', $secret);
     }
 }
開發者ID:WYSAC,項目名稱:oregon-owncloud,代碼行數:10,代碼來源:repairconfig.php

示例2: sendEmail

 public static function sendEmail($args)
 {
     $isEncrypted = \OC_App::isEnabled('files_encryption');
     if (!$isEncrypted || isset($_POST['continue'])) {
         $continue = true;
     } else {
         $continue = false;
     }
     if (\OC_User::userExists($_POST['user']) && $continue) {
         $token = hash('sha256', \OC_Util::generateRandomBytes(30) . \OC_Config::getValue('passwordsalt', ''));
         \OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', hash('sha256', $token));
         // Hash the token again to prevent timing attacks
         $email = \OC_Preferences::getValue($_POST['user'], 'settings', 'email', '');
         if (!empty($email)) {
             $link = \OC_Helper::linkToRoute('core_lostpassword_reset', array('user' => $_POST['user'], 'token' => $token));
             $link = \OC_Helper::makeURLAbsolute($link);
             $tmpl = new \OC_Template('core/lostpassword', 'email');
             $tmpl->assign('link', $link, false);
             $msg = $tmpl->fetchPage();
             $l = \OC_L10N::get('core');
             $from = \OCP\Util::getDefaultEmailAddress('lostpassword-noreply');
             try {
                 $defaults = new \OC_Defaults();
                 \OC_Mail::send($email, $_POST['user'], $l->t('%s password reset', array($defaults->getName())), $msg, $from, $defaults->getName());
             } catch (Exception $e) {
                 \OC_Template::printErrorPage('A problem occurs during sending the e-mail please contact your administrator.');
             }
             self::displayLostPasswordPage(false, true);
         } else {
             self::displayLostPasswordPage(true, false);
         }
     } else {
         self::displayLostPasswordPage(true, false);
     }
 }
開發者ID:omusico,項目名稱:isle-web-framework,代碼行數:35,代碼來源:controller.php

示例3: post_login

 public static function post_login($parameters)
 {
     $uid = $parameters['uid'];
     $casBackend = OC_USER_CAS::getInstance();
     $userDatabase = new OC_User_Database();
     if (phpCAS::isAuthenticated()) {
         // $cas_attributes may vary in name, therefore attributes are fetched to $attributes
         $cas_attributes = phpCAS::getAttributes();
         $cas_uid = phpCAS::getUser();
         // parameters
         $attributes = array();
         if ($cas_uid == $uid) {
             OC_Log::write('cas', 'attr  \\"' . implode(',', $cas_attributes) . '\\" for the user: ' . $uid, OC_Log::DEBUG);
             if (array_key_exists($casBackend->displayNameMapping, $cas_attributes)) {
                 $attributes['cas_name'] = $cas_attributes[$casBackend->displayNameMapping];
             } else {
                 $attributes['cas_name'] = $cas_attributes['cn'];
             }
             if (array_key_exists($casBackend->mailMapping, $cas_attributes)) {
                 $attributes['cas_email'] = $cas_attributes[$casBackend->mailMapping];
             } else {
                 $attributes['cas_email'] = $cas_attributes['mail'];
             }
             if (array_key_exists($casBackend->groupMapping, $cas_attributes)) {
                 $attributes['cas_groups'] = $cas_attributes[$casBackend->groupMapping];
             } else {
                 if (!empty($casBackend->defaultGroup)) {
                     $attributes['cas_groups'] = array($casBackend->defaultGroup);
                     OC_Log::write('cas', 'Using default group "' . $casBackend->defaultGroup . '" for the user: ' . $uid, OC_Log::DEBUG);
                 }
             }
             if (!$userDatabase->userExists($uid) && $casBackend->autocreate) {
                 // create users if they do not exist
                 if (preg_match('/[^a-zA-Z0-9 _\\.@\\-]/', $uid)) {
                     OC_Log::write('cas', 'Invalid username "' . $uid . '", allowed chars "a-zA-Z0-9" and "_.@-" ', OC_Log::DEBUG);
                     return false;
                 } else {
                     $random_password = OC_Util::generateRandomBytes(20);
                     OC_Log::write('cas', 'Creating new user: ' . $uid, OC_Log::DEBUG);
                     $userDatabase->createUser($uid, $random_password);
                     // after creating the user, fill the attributes
                     if ($userDatabase->userExists($uid)) {
                         OC_USER_CAS_Hooks::update_user($uid, $attributes);
                     }
                 }
             }
             // try to update user attributes
             if ($casBackend->updateUserData) {
                 OC_USER_CAS_Hooks::update_user($cas_uid, $attributes);
             }
             return true;
         }
     }
     return false;
 }
開發者ID:GIP-RECIA,項目名稱:user_cas,代碼行數:55,代碼來源:hooks.php

示例4: setupDatabase

 public function setupDatabase($username)
 {
     //check if the database user has admin right
     $connection = @mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword);
     if (!$connection) {
         throw new \OC\DatabaseSetupException($this->trans->t('MySQL/MariaDB username and/or password not valid'), $this->trans->t('You need to enter either an existing account or the administrator.'));
     }
     //user already specified in config
     $oldUser = \OC_Config::getValue('dbuser', false);
     //we don't have a dbuser specified in config
     if ($this->dbuser != $oldUser) {
         //add prefix to the admin username to prevent collisions
         $adminUser = substr('oc_' . $username, 0, 16);
         $i = 1;
         while (true) {
             //this should be enough to check for admin rights in mysql
             $query = "SELECT user FROM mysql.user WHERE user='{$adminUser}'";
             $result = mysql_query($query, $connection);
             //current dbuser has admin rights
             if ($result) {
                 //new dbuser does not exist
                 if (mysql_num_rows($result) === 0) {
                     //use the admin login data for the new database user
                     $this->dbuser = $adminUser;
                     //create a random password so we don't need to store the admin password in the config file
                     $this->dbpassword = \OC_Util::generateRandomBytes(30);
                     $this->createDBUser($connection);
                     break;
                 } else {
                     //repeat with different username
                     $length = strlen((string) $i);
                     $adminUser = substr('oc_' . $username, 0, 16 - $length) . $i;
                     $i++;
                 }
             } else {
                 break;
             }
         }
         \OC_Config::setValue('dbuser', $this->dbuser);
         \OC_Config::setValue('dbpassword', $this->dbpassword);
     }
     //create the database
     $this->createDatabase($connection);
     //fill the database if needed
     $query = 'select count(*) from information_schema.tables' . " where table_schema='" . $this->dbname . "' AND table_name = '" . $this->tableprefix . "users';";
     $result = mysql_query($query, $connection);
     if ($result) {
         $row = mysql_fetch_row($result);
     }
     if (!$result or $row[0] == 0) {
         \OC_DB::createDbFromStructure($this->dbDefinitionFile);
     }
     mysql_close($connection);
 }
開發者ID:riso,項目名稱:owncloud-core,代碼行數:54,代碼來源:mysql.php

示例5: setUp

 function setUp()
 {
     $this->username = OC_Util::generateRandomBytes(20);
     OC_User::createUser($this->username, OC_Util::generateRandomBytes(20));
     \OC_Util::tearDownFS();
     \OC_User::setUserId('');
     \OC\Files\Filesystem::tearDown();
     \OC_Util::setupFS($this->username);
     $this->user = \OC::$server->getUserManager()->get($this->username);
     $this->certificateManager = new CertificateManager($this->user);
 }
開發者ID:Combustible,項目名稱:core,代碼行數:11,代碼來源:certificatemanager.php

示例6: encrypt

 /**
  * Encrypts a value and adds an HMAC (Encrypt-Then-MAC)
  * @param string $plaintext
  * @param string $password Password to encrypt, if not specified the secret from config.php will be taken
  * @return string Authenticated ciphertext
  */
 public function encrypt($plaintext, $password = '')
 {
     if ($password === '') {
         $password = $this->config->getSystemValue('secret');
     }
     $this->cipher->setPassword($password);
     $iv = \OC_Util::generateRandomBytes($this->ivLength);
     $this->cipher->setIV($iv);
     $ciphertext = bin2hex($this->cipher->encrypt($plaintext));
     $hmac = bin2hex($this->calculateHMAC($ciphertext . $iv, $password));
     return $ciphertext . '|' . $iv . '|' . $hmac;
 }
開發者ID:WYSAC,項目名稱:oregon-owncloud,代碼行數:18,代碼來源:crypto.php

示例7: setUp

 public function setUp()
 {
     $dbfile = OC::$SERVERROOT . '/tests/data/db_structure.xml';
     $dbfile2 = OC::$SERVERROOT . '/tests/data/db_structure2.xml';
     $r = '_' . OC_Util::generateRandomBytes(4) . '_';
     $content = file_get_contents($dbfile);
     $content = str_replace('*dbprefix*', '*dbprefix*' . $r, $content);
     file_put_contents($this->schema_file, $content);
     $content = file_get_contents($dbfile2);
     $content = str_replace('*dbprefix*', '*dbprefix*' . $r, $content);
     file_put_contents($this->schema_file2, $content);
     $this->table1 = $r . 'cntcts_addrsbks';
     $this->table2 = $r . 'cntcts_cards';
 }
開發者ID:olucao,項目名稱:owncloud-core,代碼行數:14,代碼來源:dbschema.php

示例8: setUp

 public function setUp()
 {
     $dbfile = OC::$SERVERROOT . '/tests/data/db_structure.xml';
     $r = '_' . OC_Util::generateRandomBytes(4) . '_';
     $content = file_get_contents($dbfile);
     $content = str_replace('*dbprefix*', '*dbprefix*' . $r, $content);
     file_put_contents(self::$schema_file, $content);
     OC_DB::createDbFromStructure(self::$schema_file);
     $this->test_prefix = $r;
     $this->table1 = $this->test_prefix . 'cntcts_addrsbks';
     $this->table2 = $this->test_prefix . 'cntcts_cards';
     $this->table3 = $this->test_prefix . 'vcategory';
     $this->table4 = $this->test_prefix . 'decimal';
 }
開發者ID:anolisti,項目名稱:core,代碼行數:14,代碼來源:db.php

示例9: equals

 /**
  * Compares whether two strings are equal. To prevent guessing of the string
  * length this is done by comparing two hashes against each other and afterwards
  * a comparison of the real string to prevent against the unlikely chance of
  * collisions.
  *
  * Be aware that this function may leak whether the string to compare have a different
  * length.
  *
  * @param string $expected The expected value
  * @param string $input The input to compare against
  * @return bool True if the two strings are equal, otherwise false.
  */
 public static function equals($expected, $input)
 {
     if (!is_string($expected) || !is_string($input)) {
         return false;
     }
     if (function_exists('hash_equals')) {
         return hash_equals($expected, $input);
     }
     $randomString = \OC_Util::generateRandomBytes(10);
     if (hash('sha512', $expected . $randomString) === hash('sha512', $input . $randomString)) {
         if ($expected === $input) {
             return true;
         }
     }
     return false;
 }
開發者ID:WYSAC,項目名稱:oregon-owncloud,代碼行數:29,代碼來源:stringutils.php

示例10: xsetUpBeforeClass

 public static function xsetUpBeforeClass()
 {
     $dbfile = __DIR__ . '/../../appinfo/database.xml';
     self::$test_prefix = '_' . OC_Util::generateRandomBytes('4') . '_';
     $content = file_get_contents($dbfile);
     $content = str_replace('*dbprefix*', '*dbprefix*' . self::$test_prefix, $content);
     file_put_contents(self::$schema_file, $content);
     OC_DB::createDbFromStructure(self::$schema_file);
     self::$addressBooksTableName = '*PREFIX*' . self::$test_prefix . 'contacts_addressbooks';
     self::$cardsTableName = '*PREFIX*' . self::$test_prefix . 'contacts_cards';
     OC_User::clearBackends();
     OC_User::useBackend('dummy');
     self::$user = uniqid('user_');
     OC_User::createUser(self::$user, 'pass');
     OC_User::setUserId(self::$user);
     self::$backend = new OCA\Contacts\Backend\Database(self::$user, self::$addressBooksTableName, self::$cardsTableName);
 }
開發者ID:alid-wise,項目名稱:contacts,代碼行數:17,代碼來源:contacts_app.php

示例11: setupDatabase

 public function setupDatabase($username)
 {
     //check if the database user has admin right
     $connection = @mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword);
     if (!$connection) {
         throw new \DatabaseSetupException($this->trans->t('MySQL username and/or password not valid'), $this->trans->t('You need to enter either an existing account or the administrator.'));
     }
     $oldUser = \OC_Config::getValue('dbuser', false);
     //this should be enough to check for admin rights in mysql
     $query = "SELECT user FROM mysql.user WHERE user='{$this->dbuser}'";
     if (mysql_query($query, $connection)) {
         //use the admin login data for the new database user
         //add prefix to the mysql user name to prevent collisions
         $this->dbuser = substr('oc_' . $username, 0, 16);
         if ($this->dbuser != $oldUser) {
             //hash the password so we don't need to store the admin config in the config file
             $this->dbpassword = \OC_Util::generateRandomBytes(30);
             $this->createDBUser($connection);
             \OC_Config::setValue('dbuser', $this->dbuser);
             \OC_Config::setValue('dbpassword', $this->dbpassword);
         }
         //create the database
         $this->createDatabase($connection);
     } else {
         if ($this->dbuser != $oldUser) {
             \OC_Config::setValue('dbuser', $this->dbuser);
             \OC_Config::setValue('dbpassword', $this->dbpassword);
         }
         //create the database
         $this->createDatabase($connection);
     }
     //fill the database if needed
     $query = 'select count(*) from information_schema.tables' . " where table_schema='" . $this->dbname . "' AND table_name = '" . $this->tableprefix . "users';";
     $result = mysql_query($query, $connection);
     if ($result) {
         $row = mysql_fetch_row($result);
     }
     if (!$result or $row[0] == 0) {
         \OC_DB::createDbFromStructure($this->dbDefinitionFile);
     }
     mysql_close($connection);
 }
開發者ID:omusico,項目名稱:isle-web-framework,代碼行數:42,代碼來源:mysql.php

示例12: post_login

 public static function post_login($parameters)
 {
     // Do nothing if we're sharding and not on the master
     if (OCP\App::isEnabled('files_sharding') && !OCA\FilesSharding\Lib::isMaster()) {
         return true;
     }
     $uid = '';
     $userid = $parameters['uid'];
     $samlBackend = new OC_USER_SAML();
     $ocUserDatabase = new OC_User_Database();
     // Redirect regardless of whether the user has authenticated with SAML or not.
     // Since this is a post_login hook, he will have authenticated in some way and have a valid session.
     if ($ocUserDatabase->userExists($userid)) {
         // Set user attributes for sharding
         $display_name = \OCP\User::getDisplayName($userid);
         $email = \OCP\Config::getUserValue($userid, 'settings', 'email');
         $groups = \OC_Group::getUserGroups($userid);
         $quota = \OC_Preferences::getValue($userid, 'files', 'quota');
         OC_Util::teardownFS($userid);
         OC_Util::setupFS($userid);
         OC_Log::write('saml', 'Setting user attributes: ' . $userid . ":" . $display_name . ":" . $email . ":" . join($groups) . ":" . $quota, OC_Log::INFO);
         self::setAttributes($userid, $display_name, $email, $groups, $quota);
         self::user_redirect($userid);
     }
     if (!$samlBackend->auth->isAuthenticated()) {
         return false;
     }
     $attributes = $samlBackend->auth->getAttributes();
     //$email = "<pre>" . print_r($attributes, 1) . "</pre>";
     //$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
     //error_log($email, 1, 'cbri@dtu.dk', $headers);
     $usernameFound = false;
     foreach ($samlBackend->usernameMapping as $usernameMapping) {
         if (array_key_exists($usernameMapping, $attributes) && !empty($attributes[$usernameMapping][0])) {
             $usernameFound = true;
             $uid = $attributes[$usernameMapping][0];
             OC_Log::write('saml', 'Authenticated user ' . $uid, OC_Log::INFO);
             break;
         }
     }
     if (!$usernameFound || $uid !== $userid) {
         return false;
     }
     $attrs = self::get_user_attributes($uid, $samlBackend);
     if (!$ocUserDatabase->userExists($uid)) {
         // If autocreate is not enabled - back off
         if (!$samlBackend->autocreate) {
             return false;
         }
         // Apparently it is necessary to clear the uid first, to be able to create the user in the DB
         $userManager = \OC_User::getManager();
         $userManager->delete($uid);
         // Reject invalid user names
         if (preg_match('/[^a-zA-Z0-9 _\\.@\\-]/', $uid)) {
             OC_Log::write('saml', 'Invalid username "' . $uid . '", allowed chars "a-zA-Z0-9" and "_.@-" ', OC_Log::DEBUG);
             return false;
         }
         $cookiedomain = OCP\App::isEnabled('files_sharding') ? OCA\FilesSharding\Lib::getCookieDomain() : null;
         // Reject users we don't allow to autocreate an account
         if (isset($uid) && trim($uid) != '' && !OC_User::userExists($uid) && !self::check_user_attributes($attributes)) {
             $failCookieName = 'saml_auth_fail';
             $userCookieName = 'saml_auth_fail_user';
             $expire = 0;
             //time()+60*60*24*30;
             $expired = time() - 3600;
             $path = '/';
             setcookie($failCookieName, "notallowed:" . $uid, $expire, $path, $cookiedomain, false, false);
             setcookie($userCookieName, $uid, $expire, $path, $cookiedomain, false, false);
             $spSource = 'default-sp';
             $auth = new SimpleSAML_Auth_Simple($spSource);
             OC_Log::write('saml', 'Rejected user "' . $uid, OC_Log::ERROR);
             if (OCP\App::isEnabled('files_sharding') && !OCA\FilesSharding\Lib::isMaster()) {
                 $auth->logout(!OCA\FilesSharding\Lib::getMasterURL());
             } else {
                 $auth->logout();
             }
             return false;
         }
         // Create new user
         $random_password = OC_Util::generateRandomBytes(20);
         OC_Log::write('saml', 'Creating new user: ' . $uid, OC_Log::WARN);
         OC_User::createUser($uid, $random_password);
         if (OC_User::userExists($uid)) {
             $userDir = '/' . $uid . '/files';
             \OC\Files\Filesystem::init($uid, $userDir);
             if ($samlBackend->updateUserData) {
                 self::update_user_data($uid, $samlBackend, $attrs, true);
                 if (OCP\App::isEnabled('files_sharding') && OCA\FilesSharding\Lib::isMaster()) {
                     $master_site = OCA\FilesSharding\Lib::dbGetSite(null);
                     $server_id = OCA\FilesSharding\Lib::dbChooseServerForUser($uid, $master_site, 0, null);
                     OC_Log::write('saml', 'Setting server for new user: ' . $master_site . ":" . $server_id, OC_Log::WARN);
                     OCA\FilesSharding\Lib::dbSetServerForUser($uid, $server_id, 0);
                 }
             }
             self::setAttributes($uid, $attrs['display_name'], $attrs['email'], $attrs['groups'], $attrs['quota']);
         }
     } else {
         if ($samlBackend->updateUserData) {
             self::update_user_data($uid, $samlBackend, $attrs, false);
         }
//.........這裏部分代碼省略.........
開發者ID:AARNet,項目名稱:user_saml,代碼行數:101,代碼來源:hooks.php

示例13: post_login

 public static function post_login($parameters)
 {
     $uid = $parameters['uid'];
     $wuid = $uid;
     $casBackend = new OC_USER_CAS();
     $userDB = new OC_User_Database();
     /*
      * Récupération des données du fichier config général /config/config.php
      */
     $serveur_Search = OCP\Config::getSystemValue('serveur_Search', 'error');
     $port = OCP\Config::getSystemValue('port', 'error');
     $racineAMU = OCP\Config::getSystemValue('racineAMU', 'error');
     $racineAMUGRP = OCP\Config::getSystemValue('racineAMUGRP', 'error');
     $AMU_nuage_dn = OCP\Config::getSystemValue('AMU_nuage_dn', 'error');
     $AMU_nuage_pw = OCP\Config::getSystemValue('AMU_nuage_pw', 'error');
     $PQuota = OCP\Config::getSystemValue('PQuota', 'unManaged');
     $EQuota = OCP\Config::getSystemValue('EQuota', 'unManaged');
     $LDAP = new LDAP_Infos($serveur_Search, $AMU_nuage_dn, $AMU_nuage_pw, $racineAMUGRP, $racineAMUGRP);
     $restrictGrp = array("cn", "member");
     /*
      * Récupération tableau Groupes
      * Si le tableau 'groupMapping' est vide pas de contrôle sur les groupes
      */
     $AccesCloud = 0;
     OCP\Util::writeLog('user_cas', "Authentification (Mapping groups=" . $casBackend->groupMapping . ")", OCP\Util::DEBUG);
     if ($casBackend->groupMapping) {
         $wTabGrp = str_replace(array('<br>', '<br />', "\n", "\r"), array('@', '', '@', ''), $casBackend->groupMapping);
         $tabGRP = explode("@", $wTabGrp);
         $i = 0;
         $mesGroupes = array();
         foreach ($tabGRP as $key => $value) {
             $ListeMembre = $LDAP->getMembersOfGroup($value, $restrictGrp);
             if (in_array($uid, $ListeMembre)) {
                 $AccesCloudAMU = 1;
             }
         }
     } else {
         $AccesCloud = 1;
     }
     /*
      * Si pas d'acces, alors déconnexion
      */
     if ($AccesCloud == 0) {
         /*
          * On vérifie si le compte utilisé est un compte local
          */
         if (!$userDB->userExists($uid)) {
             OCP\Util::writeLog('user_cas', "Aucun droit d'accès pour l'utilisateur " . $uid, OCP\Util::ERROR);
             \OC_User::logout();
         } else {
             OCP\Util::writeLog('user_cas', "Authentification locale pour l'utilisateur " . $uid, OCP\Util::DEBUG);
             OC::$REQUESTEDAPP = '';
             OC_Util::redirectToDefaultPage();
             exit(0);
         }
     }
     /**
      * Récupère les groupes liés à l'utilisateur avec la racine définie dans le formulaire 'cas_group_root'
      * Si 'cas_group_root' n'est pas renseingé => pas de récupération de groupes
      */
     $mesGroupes = array();
     OCP\Util::writeLog('user_cas', "Authentification (Racine Groupes LDAP=" . $casBackend->groupRoot . ")", OCP\Util::DEBUG);
     if ($casBackend->groupRoot) {
         $i = 0;
         $ListeGRP = $LDAP->getMemberOf($uid);
         $a = sizeof($ListeGRP);
         OCP\Util::writeLog('user_cas', "Taille=" . $a . " UID=" . $uid, OCP\Util::ERROR);
         OCP\Util::writeLog('user_cas', "Racine Groupe=" . $casBackend->groupRoot, OCP\Util::ERROR);
         foreach ($ListeGRP as $key => $value) {
             if (strstr($value, $casBackend->groupRoot)) {
                 $mesGroupes[$i] = strtoupper(str_replace(':', '_', substr($value, 8)));
                 OCP\Util::writeLog('user_cas', "Groupe[{$i}]=" . $mesGroupes[$i], OCP\Util::ERROR);
                 $i++;
             }
         }
     }
     if (phpCAS::checkAuthentication()) {
         //$attributes = phpCAS::getAttributes();
         $cas_uid = phpCAS::getUser();
         if ($cas_uid == $uid) {
             /*
              * Récupération des information utilisateur (LDAP)
              */
             $tabLdapUser = $LDAP->getUserInfo($uid);
             if ($tabLdapUser) {
                 $DisplayName = $tabLdapUser['displayName'];
             }
             if (!$userDB->userExists($uid)) {
                 if (preg_match('/[^a-zA-Z0-9 _\\.@\\-]/', $uid)) {
                     OCP\Util::writeLog('cas', 'Utilisateur  invalide "' . $uid . '", caracteres autorises "a-zA-Z0-9" and "_.@-" ', OCP\Util::DEBUG);
                     return false;
                 } else {
                     /*
                      * Dans le cas d'une création
                      */
                     $random_password = \OC_Util::generateRandomBytes(20);
                     $userDB->createUser($uid, $tabLdapUser['userpassword']);
                     $userDB->setDisplayName($uid, $DisplayName);
                     /*
                      * Mise à jour du quota si gestion dans fichier de configuration
//.........這裏部分代碼省略.........
開發者ID:jas01,項目名稱:user_cas,代碼行數:101,代碼來源:hooks.php

示例14: install

 /**
  * @param $options
  * @return array
  */
 public static function install($options)
 {
     $l = self::getTrans();
     $error = array();
     $dbtype = $options['dbtype'];
     if (empty($options['adminlogin'])) {
         $error[] = $l->t('Set an admin username.');
     }
     if (empty($options['adminpass'])) {
         $error[] = $l->t('Set an admin password.');
     }
     if (empty($options['directory'])) {
         $options['directory'] = OC::$SERVERROOT . "/data";
     }
     if (!isset(self::$dbSetupClasses[$dbtype])) {
         $dbtype = 'sqlite';
     }
     $username = htmlspecialchars_decode($options['adminlogin']);
     $password = htmlspecialchars_decode($options['adminpass']);
     $datadir = htmlspecialchars_decode($options['directory']);
     $class = self::$dbSetupClasses[$dbtype];
     /** @var \OC\Setup\AbstractDatabase $dbSetup */
     $dbSetup = new $class(self::getTrans(), 'db_structure.xml');
     $error = array_merge($error, $dbSetup->validate($options));
     // validate the data directory
     if (!is_dir($datadir) and !mkdir($datadir) or !is_writable($datadir)) {
         $error[] = $l->t("Can't create or write into the data directory %s", array($datadir));
     }
     if (count($error) != 0) {
         return $error;
     }
     //no errors, good
     if (isset($options['trusted_domains']) && is_array($options['trusted_domains'])) {
         $trustedDomains = $options['trusted_domains'];
     } else {
         $trustedDomains = array(\OC_Request::getDomainWithoutPort(\OC_Request::serverHost()));
     }
     if (OC_Util::runningOnWindows()) {
         $datadir = rtrim(realpath($datadir), '\\');
     }
     //use sqlite3 when available, otherise sqlite2 will be used.
     if ($dbtype == 'sqlite' and class_exists('SQLite3')) {
         $dbtype = 'sqlite3';
     }
     //generate a random salt that is used to salt the local user passwords
     $salt = OC_Util::generateRandomBytes(30);
     OC_Config::setValue('passwordsalt', $salt);
     OC_Config::setValue('secret', OC_Util::generateRandomBytes(96));
     //write the config file
     OC_Config::setValue('trusted_domains', $trustedDomains);
     OC_Config::setValue('datadirectory', $datadir);
     OC_Config::setValue('overwrite.cli.url', \OC_Request::serverProtocol() . '://' . \OC_Request::serverHost() . OC::$WEBROOT);
     OC_Config::setValue('dbtype', $dbtype);
     OC_Config::setValue('version', implode('.', OC_Util::getVersion()));
     try {
         $dbSetup->initialize($options);
         $dbSetup->setupDatabase($username);
     } catch (DatabaseSetupException $e) {
         $error[] = array('error' => $e->getMessage(), 'hint' => $e->getHint());
         return $error;
     } catch (Exception $e) {
         $error[] = array('error' => 'Error while trying to create admin user: ' . $e->getMessage(), 'hint' => '');
         return $error;
     }
     //create the user and group
     try {
         OC_User::createUser($username, $password);
     } catch (Exception $exception) {
         $error[] = $exception->getMessage();
     }
     if (count($error) == 0) {
         $appConfig = \OC::$server->getAppConfig();
         $appConfig->setValue('core', 'installedat', microtime(true));
         $appConfig->setValue('core', 'lastupdatedat', microtime(true));
         OC_Group::createGroup('admin');
         OC_Group::addToGroup($username, 'admin');
         OC_User::login($username, $password);
         //guess what this does
         OC_Installer::installShippedApps();
         // create empty file in data dir, so we can later find
         // out that this is indeed an ownCloud data directory
         file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT . '/data') . '/.ocdata', '');
         // Update htaccess files for apache hosts
         if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) {
             self::updateHtaccess();
             self::protectDataDirectory();
         }
         //and we are done
         OC_Config::setValue('installed', true);
     }
     return $error;
 }
開發者ID:droiter,項目名稱:openwrt-on-android,代碼行數:96,代碼來源:setup.php

示例15: tryFormLogin

	/**
	 * Tries to login a user using the formbased authentication
	 * @return bool|void
	 */
	protected static function tryFormLogin() {
		if (!isset($_POST["user"]) || !isset($_POST['password'])) {
			return false;
		}

		if(!OC_Util::isCallRegistered()) {
			return false;
		}
		OC_App::loadApps();

		//setup extra user backends
		OC_User::setupBackends();

		if (OC_User::login($_POST["user"], $_POST["password"])) {
			// setting up the time zone
			if (isset($_POST['timezone-offset'])) {
				self::$session->set('timezone', $_POST['timezone-offset']);
			}

			$userid = OC_User::getUser();
			self::cleanupLoginTokens($userid);
			if (!empty($_POST["remember_login"])) {
				if (defined("DEBUG") && DEBUG) {
					OC_Log::write('core', 'Setting remember login to cookie', OC_Log::DEBUG);
				}
				$token = OC_Util::generateRandomBytes(32);
				OC_Preferences::setValue($userid, 'login_token', $token, time());
				OC_User::setMagicInCookie($userid, $token);
			} else {
				OC_User::unsetMagicInCookie();
			}
			OC_Util::redirectToDefaultPage();
			exit();
		}
		return true;
	}
開發者ID:pombredanne,項目名稱:ArcherSys,代碼行數:40,代碼來源:base.php


注:本文中的OC_Util::generateRandomBytes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。