当前位置: 首页>>代码示例>>PHP>>正文


PHP eZUser::createHash方法代码示例

本文整理汇总了PHP中eZUser::createHash方法的典型用法代码示例。如果您正苦于以下问题:PHP eZUser::createHash方法的具体用法?PHP eZUser::createHash怎么用?PHP eZUser::createHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eZUser的用法示例。


在下文中一共展示了eZUser::createHash方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: process

 /**
  * Main method to process current row returned by getNextRow() method.
  * You may throw an exception if something goes wrong. It will be logged but won't break the import process
  * @param mixed $row Depending on your data format, can be DOMNode, SimpleXMLIterator, SimpleXMLElement, CSV row...
  */
 public function process($row)
 {
     $contentOptions = new SQLIContentOptions(array('class_identifier' => 'user', 'remote_id' => (string) $row->login));
     $content = SQLIContent::create($contentOptions);
     $content->fields->first_name = (string) $row->firstName;
     $content->fields->last_name = (string) $row->lastName;
     $userParts = array((string) $row->login, (string) $row->email);
     //password management : if empty, generate it, use custom default or fixed default
     $password = $row->password;
     if (!$password) {
         if (isset($this->options->generate_password) && $this->options->generate_password) {
             $password = eZUser::createPassword(6);
         } elseif (isset($this->options->default_password) && $this->options->default_password) {
             $password = $this->options->default_password;
         } else {
             $password = '_ezpassword';
         }
     }
     $userParts[] = $password;
     $userParts[] = eZUser::createHash((string) $row->login, $password, eZUser::site(), eZUser::hashType());
     $userParts[] = eZUser::hashType();
     $content->fields->user_account = implode('|', $userParts);
     // Now publish content
     $content->addLocation(SQLILocation::fromNodeID($this->handlerConfArray['DefaultParentNodeID']));
     $publisher = SQLIContentPublisher::getInstance();
     $publisher->publish($content);
     // Free some memory. Internal methods eZContentObject::clearCache() and eZContentObject::resetDataMap() will be called
     // @see SQLIContent::__destruct()
     unset($content);
     $this->csv->rows->next();
 }
开发者ID:heliopsis,项目名称:SQLIImport,代码行数:36,代码来源:sqliusersimporthandler.php

示例2: authenticateHash

 static function authenticateHash($user, $password, $site, $type, $hash)
 {
     return eZUser::createHash($user, $password, $site, $type, $hash) === (string) $hash;
 }
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:4,代码来源:ezuser.php

示例3: loginUser

 static function loginUser($login, $password, $authenticationMatch = false)
 {
     $http = eZHTTPTool::instance();
     $db = eZDB::instance();
     if ($authenticationMatch === false) {
         $authenticationMatch = eZUser::authenticationMatch();
     }
     $loginEscaped = $db->escapeString($login);
     $passwordEscaped = $db->escapeString($password);
     $loginArray = array();
     if ($authenticationMatch & eZUser::AUTHENTICATE_LOGIN) {
         $loginArray[] = "login='{$loginEscaped}'";
     }
     if ($authenticationMatch & eZUser::AUTHENTICATE_EMAIL) {
         $loginArray[] = "email='{$loginEscaped}'";
     }
     if (count($loginArray) == 0) {
         $loginArray[] = "login='{$loginEscaped}'";
     }
     $loginText = implode(' OR ', $loginArray);
     $contentObjectStatus = eZContentObject::STATUS_PUBLISHED;
     $ini = eZINI::instance();
     $textFileIni = eZINI::instance('textfile.ini');
     $databaseName = $db->databaseName();
     // if mysql
     if ($databaseName === 'mysql') {
         $query = "SELECT contentobject_id, password_hash, password_hash_type, email, login\n                      FROM ezuser, ezcontentobject\n                      WHERE ( {$loginText} ) AND\n                        ezcontentobject.status='{$contentObjectStatus}' AND\n                        ( ezcontentobject.id=contentobject_id OR ( password_hash_type=4 AND ( {$loginText} ) AND password_hash=PASSWORD('{$passwordEscaped}') ) )";
     } else {
         $query = "SELECT contentobject_id, password_hash, password_hash_type, email, login\n                      FROM ezuser, ezcontentobject\n                      WHERE ( {$loginText} ) AND\n                            ezcontentobject.status='{$contentObjectStatus}' AND\n                            ezcontentobject.id=contentobject_id";
     }
     $users = $db->arrayQuery($query);
     $exists = false;
     if (count($users) >= 1) {
         foreach ($users as $userRow) {
             $userID = $userRow['contentobject_id'];
             $hashType = $userRow['password_hash_type'];
             $hash = $userRow['password_hash'];
             $exists = eZUser::authenticateHash($userRow['login'], $password, eZUser::site(), $hashType, $hash);
             // If hash type is MySql
             if ($hashType == eZUser::PASSWORD_HASH_MYSQL and $databaseName === 'mysql') {
                 $queryMysqlUser = "SELECT contentobject_id, password_hash, password_hash_type, email, login\n                                       FROM ezuser, ezcontentobject\n                                       WHERE ezcontentobject.status='{$contentObjectStatus}' AND\n                                             password_hash_type=4 AND ( {$loginText} ) AND password_hash=PASSWORD('{$passwordEscaped}') ";
                 $mysqlUsers = $db->arrayQuery($queryMysqlUser);
                 if (count($mysqlUsers) >= 1) {
                     $exists = true;
                 }
             }
             eZDebugSetting::writeDebug('kernel-user', eZUser::createHash($userRow['login'], $password, eZUser::site(), $hashType), "check hash");
             eZDebugSetting::writeDebug('kernel-user', $hash, "stored hash");
             // If current user has been disabled after a few failed login attempts.
             $canLogin = eZUser::isEnabledAfterFailedLogin($userID);
             if ($exists) {
                 // We should store userID for warning message.
                 $GLOBALS['eZFailedLoginAttemptUserID'] = $userID;
                 $userSetting = eZUserSetting::fetch($userID);
                 $isEnabled = $userSetting->attribute("is_enabled");
                 if ($hashType != eZUser::hashType() and strtolower($ini->variable('UserSettings', 'UpdateHash')) == 'true') {
                     $hashType = eZUser::hashType();
                     $hash = eZUser::createHash($login, $password, eZUser::site(), $hashType);
                     $db->query("UPDATE ezuser SET password_hash='{$hash}', password_hash_type='{$hashType}' WHERE contentobject_id='{$userID}'");
                 }
                 break;
             }
         }
     }
     if ($exists and $isEnabled and $canLogin) {
         eZDebugSetting::writeDebug('kernel-user', $userRow, 'user row');
         $user = new eZUser($userRow);
         eZDebugSetting::writeDebug('kernel-user', $user, 'user');
         $userID = $user->attribute('contentobject_id');
         eZUser::updateLastVisit($userID);
         eZUser::setCurrentlyLoggedInUser($user, $userID);
         // Reset number of failed login attempts
         eZUser::setFailedLoginAttempts($userID, 0);
         return $user;
     } else {
         if ($textFileIni->variable('TextFileSettings', 'TextFileEnabled') == "true") {
             $fileName = $textFileIni->variable('TextFileSettings', 'FileName');
             $filePath = $textFileIni->variable('TextFileSettings', 'FilePath');
             $defaultUserPlacement = $ini->variable("UserSettings", "DefaultUserPlacement");
             $separator = $textFileIni->variable("TextFileSettings", "FileFieldSeparator");
             $loginColumnNr = $textFileIni->variable("TextFileSettings", "LoginAttribute");
             $passwordColumnNr = $textFileIni->variable("TextFileSettings", "PasswordAttribute");
             $emailColumnNr = $textFileIni->variable("TextFileSettings", "EmailAttribute");
             $lastNameColumnNr = $textFileIni->variable("TextFileSettings", "LastNameAttribute");
             $firstNameColumnNr = $textFileIni->variable("TextFileSettings", "FirstNameAttribute");
             if ($textFileIni->hasVariable('TextFileSettings', 'DefaultUserGroupType')) {
                 $UserGroupType = $textFileIni->variable('TextFileSettings', 'DefaultUserGroupType');
                 $UserGroup = $textFileIni->variable('TextFileSettings', 'DefaultUserGroup');
             }
             if ($UserGroupType != null) {
                 if ($UserGroupType == "name") {
                     $groupName = $UserGroup;
                     $groupQuery = "SELECT ezcontentobject_tree.node_id\n                                       FROM ezcontentobject, ezcontentobject_tree\n                                       WHERE ezcontentobject.name='{$groupName}'\n                                       AND ezcontentobject.id=ezcontentobject_tree.contentobject_id";
                     $groupObject = $db->arrayQuery($groupQuery);
                     if (count($groupObject) > 0) {
                         $defaultUserPlacement = $groupObject[0]['node_id'];
                     }
                 } else {
                     if ($UserGroupType == "id") {
                         $groupID = $UserGroup;
//.........这里部分代码省略.........
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:101,代码来源:eztextfileuser.php

示例4: testCreateHash

 /**
  * Unit test for eZUser::createHash()
  * @dataProvider hashDataProvider
  */
 public function testCreateHash($user, $password, $site, $type, $hash, $expected)
 {
     $this->assertSame($expected, eZUser::createHash($user, $password, $site, $type, $hash));
 }
开发者ID:runelangseid,项目名称:ezpublish,代码行数:8,代码来源:ezuserauthentication_test.php

示例5: importAttribute

/**
 * Imports a value to an attribute adapting it to the proper type.
 * Not written by me, downloaded from ez.no! Extended it only!
 * @param data The value (string/int/float).
 * @param contentObjectAttribute The attribute to modify.
 */
function importAttribute($data, &$contentObjectAttribute)
{
    $contentClassAttribute = $contentObjectAttribute->attribute('contentclass_attribute');
    $dataTypeString = $contentClassAttribute->attribute('data_type_string');
    ezDebug::writeDebug("Converting " . $data . " to expected " . $dataTypeString);
    switch ($dataTypeString) {
        case 'ezfloat':
        case 'ezprice':
            $contentObjectAttribute->setAttribute('data_float', $data);
            $contentObjectAttribute->store();
            break;
        case 'ezboolean':
        case 'ezdate':
        case 'ezdatetime':
        case 'ezinteger':
        case 'ezsubtreesubscription':
        case 'eztime':
            $contentObjectAttribute->setAttribute('data_int', $data);
            $contentObjectAttribute->store();
            break;
        case 'ezobjectrelation':
            // $data is contentobject_id to relate to
            //            $oldData = $contentObjectAttribute->attribute( 'data_int' );
            $contentObjectAttribute->setAttribute('data_int', $data);
            $contentObjectAttribute->store();
            $object = $contentObjectAttribute->object();
            $contentObjectVersion = $contentObjectAttribute->attribute('version');
            $contentClassAttributeID = $contentObjectAttribute->attribute('contentclassattribute_id');
            // Problem with translations if removing old relations ?!
            //            $object->removeContentObjectRelation( $oldData, $contentObjectVersion, $contentClassAttributeID, eZContentObject::RELATION_ATTRIBUTE );
            $object->addContentObjectRelation($data, $contentObjectVersion, $contentClassAttributeID, RELATION_ATTRIBUTE);
            break;
        case 'ezurl':
            $urlID = eZURL::registerURL($data);
            $contentObjectAttribute->setAttribute('data_int', $urlID);
            // Fall through to set data_text
        // Fall through to set data_text
        case 'ezemail':
        case 'ezisbn':
        case 'ezstring':
        case 'eztext':
            $contentObjectAttribute->setAttribute('data_text', $data);
            $contentObjectAttribute->store();
            break;
        case 'ezxmltext':
            /*            $parser = new eZXMLInputParser();
                    $document = $parser->process( $data );
                    $data = eZXMLTextType::domString( $document );
                    $contentObjectAttribute->fromString( $data );*/
            $contentObjectAttribute->setAttribute('data_text', $data);
            $contentObjectAttribute->store();
            break;
            //    case 'ezimage':
            //        $this->saveImage( $data, $contentObjectAttribute );
            //        break;
            //    case 'ezbinaryfile':
            //        $this->saveFile( $data, $contentObjectAttribute );
            //        break;
            //    case 'ezenum':
            //removed enum - function can be found at ez.no
            //        break;
        //    case 'ezimage':
        //        $this->saveImage( $data, $contentObjectAttribute );
        //        break;
        //    case 'ezbinaryfile':
        //        $this->saveFile( $data, $contentObjectAttribute );
        //        break;
        //    case 'ezenum':
        //removed enum - function can be found at ez.no
        //        break;
        case 'ezuser':
            // $data is assumed to be an associative array( login, password, email );
            $user = new eZUser($contentObjectAttribute->attribute('contentobject_id'));
            if (isset($data['login'])) {
                $user->setAttribute('login', $data['login']);
            }
            if (isset($data['email'])) {
                $user->setAttribute('email', $data['email']);
            }
            if (isset($data['password'])) {
                $hashType = eZUser::hashType() . '';
                $newHash = $user->createHash($data['login'], $data['password'], eZUser::site(), $hashType);
                $user->setAttribute('password_hash_type', $hashType);
                $user->setAttribute('password_hash', $newHash);
            }
            $user->store();
            break;
        default:
            die('Can not store ' . $data . ' as datatype: ' . $dataTypeString);
    }
}
开发者ID:informaticatrentina,项目名称:batchtool,代码行数:97,代码来源:lib.php

示例6: loginUser

 static function loginUser($login, $password, $authenticationMatch = false)
 {
     $http = eZHTTPTool::instance();
     $db = eZDB::instance();
     if ($authenticationMatch === false) {
         $authenticationMatch = eZUser::authenticationMatch();
     }
     $loginEscaped = $db->escapeString($login);
     $passwordEscaped = $db->escapeString($password);
     $loginLdapEscaped = self::ldap_escape($login);
     $loginArray = array();
     if ($authenticationMatch & eZUser::AUTHENTICATE_LOGIN) {
         $loginArray[] = "login='{$loginEscaped}'";
     }
     if ($authenticationMatch & eZUser::AUTHENTICATE_EMAIL) {
         $loginArray[] = "email='{$loginEscaped}'";
     }
     if (count($loginArray) == 0) {
         $loginArray[] = "login='{$loginEscaped}'";
     }
     $loginText = implode(' OR ', $loginArray);
     $contentObjectStatus = eZContentObject::STATUS_PUBLISHED;
     $ini = eZINI::instance();
     $LDAPIni = eZINI::instance('ldap.ini');
     $databaseName = $db->databaseName();
     // if mysql
     if ($databaseName === 'mysql') {
         $query = "SELECT contentobject_id, password_hash, password_hash_type, email, login\n                      FROM ezuser, ezcontentobject\n                      WHERE ( {$loginText} ) AND\n                            ezcontentobject.status='{$contentObjectStatus}' AND\n                            ( ezcontentobject.id=contentobject_id OR ( password_hash_type=4 AND ( {$loginText} ) AND password_hash=PASSWORD('{$passwordEscaped}') ) )";
     } else {
         $query = "SELECT contentobject_id, password_hash, password_hash_type, email, login\n                      FROM ezuser, ezcontentobject\n                      WHERE ( {$loginText} ) AND\n                            ezcontentobject.status='{$contentObjectStatus}' AND\n                            ezcontentobject.id=contentobject_id";
     }
     $users = $db->arrayQuery($query);
     $exists = false;
     if (count($users) >= 1) {
         foreach ($users as $userRow) {
             $userID = $userRow['contentobject_id'];
             $hashType = $userRow['password_hash_type'];
             $hash = $userRow['password_hash'];
             $exists = eZUser::authenticateHash($userRow['login'], $password, eZUser::site(), $hashType, $hash);
             // If hash type is MySql
             if ($hashType == eZUser::PASSWORD_HASH_MYSQL and $databaseName === 'mysql') {
                 $queryMysqlUser = "SELECT contentobject_id, password_hash, password_hash_type, email, login\n                                       FROM ezuser, ezcontentobject\n                                       WHERE ezcontentobject.status='{$contentObjectStatus}' AND\n                                             password_hash_type=4 AND ( {$loginText} ) AND password_hash=PASSWORD('{$passwordEscaped}') ";
                 $mysqlUsers = $db->arrayQuery($queryMysqlUser);
                 if (count($mysqlUsers) >= 1) {
                     $exists = true;
                 }
             }
             eZDebugSetting::writeDebug('kernel-user', eZUser::createHash($userRow['login'], $password, eZUser::site(), $hashType), "check hash");
             eZDebugSetting::writeDebug('kernel-user', $hash, "stored hash");
             // If current user has been disabled after a few failed login attempts.
             $canLogin = eZUser::isEnabledAfterFailedLogin($userID);
             if ($exists) {
                 // We should store userID for warning message.
                 $GLOBALS['eZFailedLoginAttemptUserID'] = $userID;
                 $userSetting = eZUserSetting::fetch($userID);
                 $isEnabled = $userSetting->attribute("is_enabled");
                 if ($hashType != eZUser::hashType() and strtolower($ini->variable('UserSettings', 'UpdateHash')) == 'true') {
                     $hashType = eZUser::hashType();
                     $hash = eZUser::createHash($login, $password, eZUser::site(), $hashType);
                     $db->query("UPDATE ezuser SET password_hash='{$hash}', password_hash_type='{$hashType}' WHERE contentobject_id='{$userID}'");
                 }
                 break;
             }
         }
     }
     if ($exists and $isEnabled and $canLogin) {
         eZDebugSetting::writeDebug('kernel-user', $userRow, 'user row');
         $user = new eZUser($userRow);
         eZDebugSetting::writeDebug('kernel-user', $user, 'user');
         $userID = $user->attribute('contentobject_id');
         eZUser::updateLastVisit($userID);
         eZUser::setCurrentlyLoggedInUser($user, $userID);
         // Reset number of failed login attempts
         eZUser::setFailedLoginAttempts($userID, 0);
         return $user;
     } else {
         if ($LDAPIni->variable('LDAPSettings', 'LDAPEnabled') === 'true') {
             // read LDAP ini settings
             // and then try to bind to the ldap server
             $LDAPDebugTrace = $LDAPIni->variable('LDAPSettings', 'LDAPDebugTrace') === 'enabled';
             $LDAPVersion = $LDAPIni->variable('LDAPSettings', 'LDAPVersion');
             $LDAPServer = $LDAPIni->variable('LDAPSettings', 'LDAPServer');
             $LDAPPort = $LDAPIni->variable('LDAPSettings', 'LDAPPort');
             $LDAPFollowReferrals = (int) $LDAPIni->variable('LDAPSettings', 'LDAPFollowReferrals');
             $LDAPBaseDN = $LDAPIni->variable('LDAPSettings', 'LDAPBaseDn');
             $LDAPBindUser = $LDAPIni->variable('LDAPSettings', 'LDAPBindUser');
             $LDAPBindPassword = $LDAPIni->variable('LDAPSettings', 'LDAPBindPassword');
             $LDAPSearchScope = $LDAPIni->variable('LDAPSettings', 'LDAPSearchScope');
             $LDAPLoginAttribute = strtolower($LDAPIni->variable('LDAPSettings', 'LDAPLoginAttribute'));
             $LDAPFirstNameAttribute = strtolower($LDAPIni->variable('LDAPSettings', 'LDAPFirstNameAttribute'));
             $LDAPFirstNameIsCN = $LDAPIni->variable('LDAPSettings', 'LDAPFirstNameIsCommonName') === 'true';
             $LDAPLastNameAttribute = strtolower($LDAPIni->variable('LDAPSettings', 'LDAPLastNameAttribute'));
             $LDAPEmailAttribute = strtolower($LDAPIni->variable('LDAPSettings', 'LDAPEmailAttribute'));
             $defaultUserPlacement = $ini->variable("UserSettings", "DefaultUserPlacement");
             $LDAPUserGroupAttributeType = strtolower($LDAPIni->variable('LDAPSettings', 'LDAPUserGroupAttributeType'));
             $LDAPUserGroupAttribute = strtolower($LDAPIni->variable('LDAPSettings', 'LDAPUserGroupAttribute'));
             if ($LDAPIni->hasVariable('LDAPSettings', 'Utf8Encoding')) {
                 $Utf8Encoding = $LDAPIni->variable('LDAPSettings', 'Utf8Encoding');
                 if ($Utf8Encoding == "true") {
                     $isUtf8Encoding = true;
//.........这里部分代码省略.........
开发者ID:CG77,项目名称:ezpublish-legacy,代码行数:101,代码来源:ezldapuser.php

示例7: createUser

 /**
  * Helper method that creates a new user.
  * Currently only creates in users/guest_accounts.
  * First and last name will be a splitup of username
  *
  * @param string $username
  * @param string $password If not provided, uses the username as password
  * @param string $email If not provided, uses '<username><at>test.ez.no'
  *
  * @return eZContentObject
  */
 protected static function createUser($username, $password = false, $email = false)
 {
     $firstname = substr($username, 0, floor(strlen($username) / 2));
     $lastname = substr($username, ceil(strlen($username) / 2));
     if ($email === false) {
         $email = "{$username}@test.ez.no";
     }
     if ($password === false) {
         $password = $username;
     }
     $user = new ezpObject('user', eZContentObjectTreeNode::fetchByPath('users/guest_accounts'));
     $user->first_name = $firstname;
     $user->last_name = $lastname;
     $user->user_account = $account = sprintf('%s|%s|%s|%d', $username, $email, eZUser::createHash($username, $password, eZUser::site(), eZUser::PASSWORD_HASH_MD5_USER), eZUser::PASSWORD_HASH_MD5_USER);
     $user->publish();
     $user->refresh();
     return $user->object;
 }
开发者ID:netbliss,项目名称:ezmbpaex,代码行数:29,代码来源:ezpaex_test.php

示例8: trim

 $validationResult = ngConnectUserActivation::validateUserInput($http);
 if ($validationResult['status'] == 'success') {
     $user = ngConnectFunctions::createUser($authResult);
     if ($user instanceof eZUser) {
         $login = trim($http->postVariable('data_user_login'));
         $email = trim($http->postVariable('data_user_email'));
         $password = trim($http->postVariable('data_user_password'));
         if (empty($password) && $siteINI->variable('UserSettings', 'GeneratePasswordIfEmpty') == 'true') {
             $password = $user->createPassword($siteINI->variable('UserSettings', 'GeneratePasswordLength'));
         }
         // we created the new account, but still need to set things up so users can login using a regular login form
         $db = eZDB::instance();
         $db->begin();
         $user->setAttribute('login', $login);
         $user->setAttribute('email', $email);
         $user->setAttribute('password_hash', eZUser::createHash($login, $password, eZUser::site(), eZUser::hashType()));
         $user->setAttribute('password_hash_type', eZUser::hashType());
         $user->store();
         ngConnectFunctions::connectUser($user->ContentObjectID, $authResult['login_method'], $authResult['id']);
         $db->commit();
         $http->removeSessionVariable('NGConnectStartedRegistration');
         $http->removeSessionVariable('NGConnectAuthResult');
         $http->removeSessionVariable('NGConnectForceRedirect');
         $verifyUserType = $siteINI->variable('UserSettings', 'VerifyUserType');
         if ($verifyUserType === 'email' && $siteINI->hasVariable('UserSettings', 'VerifyUserEmail') && $siteINI->variable('UserSettings', 'VerifyUserEmail') !== 'enabled') {
             $verifyUserType = false;
         }
         if ($authResult['email'] == '' || $email != $authResult['email'] && $verifyUserType) {
             // we only validate the account if no email was provided by social network or entered email is not the same
             // as the one from social network and if email verification is active of course
             ngConnectUserActivation::processUserActivation($user, $siteINI->variable('UserSettings', 'GeneratePasswordIfEmpty') == 'true' ? $password : false);
开发者ID:netgen,项目名称:ngconnect,代码行数:31,代码来源:profile.php

示例9: getUserAccountString

 protected function getUserAccountString($login, $email)
 {
     $password = eZUser::createPassword(8);
     $passwordHash = eZUser::createHash($login, $password, eZUser::site(), eZUser::hashType());
     return $login . '|' . $email . '|' . $passwordHash . '|' . eZUser::passwordHashTypeName(eZUser::hashType());
 }
开发者ID:sdaoudi,项目名称:nxc_social_networks,代码行数:6,代码来源:login.php

示例10: validateObjectAttributeHTTPInput

 /**
  * Validates the input from the object edit form concerning this attribute.
  *
  * @param mixed  $http                   Class eZHTTPTool.
  * @param string $base                   Seems to be always 'ContentObjectAttribute'.
  * @param mixed  $contentObjectAttribute Class eZContentObjectAttribute.
  *
  * @return int eZInputValidator::STATE_INVALID/STATE_ACCEPTED
  */
 public function validateObjectAttributeHTTPInput($http, $base, $contentObjectAttribute)
 {
     if ($http->hasPostVariable($base . '_ymcmschapv2_data_text_' . $contentObjectAttribute->attribute('id'))) {
         $data = $http->postVariable($base . '_ymcmschapv2_data_text_' . $contentObjectAttribute->attribute('id'));
         $classAttribute = $contentObjectAttribute->contentClassAttribute();
         if ($data == "") {
             if ($contentObjectAttribute->validateIsRequired()) {
                 $contentObjectAttribute->setValidationError(ezi18n('kernel/classes/datatypes', 'Input required.'));
                 return eZInputValidator::STATE_INVALID;
             }
         } else {
             $maxLen = $classAttribute->attribute(self::MAX_LEN_FIELD);
             $textCodec = eZTextCodec::instance(false);
             if ($textCodec->strlen($data) > $maxLen and $maxLen > 0) {
                 $contentObjectAttribute->setValidationError(ezi18n('kernel/classes/datatypes', 'The input text is too long. The maximum number of characters allowed is %1.'), $maxLen);
                 return eZInputValidator::STATE_INVALID;
             }
             $minLen = $classAttribute->attribute(self::MIN_LEN_FIELD);
             if ($textCodec->strlen($data) < $minLen and $minLen > 0) {
                 $contentObjectAttribute->setValidationError(ezi18n('kernel/classes/datatypes', 'The input text is too short. The minimum number of characters is %1.'), $minLen);
                 return eZInputValidator::STATE_INVALID;
             }
             //Make the user input asomething different from his normal password //start
             //ToDo: Do not return valid if the user has changed his pwassword but the new password is not in the "_POST-Array...
             $found_login = false;
             $found_password = false;
             //ToDO: Don't walk through the $_POST-array...
             foreach ($_POST as $key => $content) {
                 if (strpos($key, '_data_user_login_') != false and $content != '') {
                     $found_login = $content;
                 } else {
                     if (strpos($key, '_data_user_password_') != false and $content != '') {
                         $found_password = $content;
                     }
                 }
             }
             if ($found_password !== false and $found_password == $data) {
                 $contentObjectAttribute->setValidationError(ezi18n('kernel/classes/datatypes', 'This has to be different from your new user account password.'));
                 return eZInputValidator::STATE_INVALID;
             } else {
                 $objectID = $contentObjectAttribute->attribute('contentobject_id');
                 include_once "kernel/classes/datatypes/ezuser/ezuser.php";
                 $user = eZUser::fetch($objectID);
                 if (is_object($user)) {
                     if ($found_login === false) {
                         $found_login = $user->attribute('login');
                     }
                     $passHash = eZUser::createHash($found_login, $data, eZUser::site(), $user->attribute('password_hash_type'));
                     if ($passHash == $user->attribute('password_hash')) {
                         $contentObjectAttribute->setValidationError(ezi18n('kernel/classes/datatypes', 'This has to be different from your current user account password.'));
                         return eZInputValidator::STATE_INVALID;
                     }
                 }
             }
             //Make the user input asomething different from his normal password //end
             return eZInputValidator::STATE_ACCEPTED;
         }
     }
     return eZInputValidator::STATE_ACCEPTED;
 }
开发者ID:kmajkowski,项目名称:ymc-ezp-datatypes,代码行数:69,代码来源:ymcmschapv2type.php


注:本文中的eZUser::createHash方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。