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


PHP UserUtil::setPassword方法代码示例

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


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

示例1: modify


//.........这里部分代码省略.........
            $this->notifyHooks($hook);
            $validators = $hook->getValidators();

            if (!$errorFields && !$validators->hasErrors()) {
                if ($originalUser['uname'] != $user['uname']) {
                    // UserUtil::setVar does not allow uname to be changed.
                    // UserUtil::setVar('uname', $user['uname'], $originalUser['uid']);
                    $updatedUserObj = array(
                        'uid'   => $originalUser['uid'],
                        'uname' => $user['uname'],
                    );
                    DBUtil::updateObject($updatedUserObj, 'users', '', 'uid');
                    $eventArgs = array(
                        'action'    => 'setVar',
                        'field'     => 'uname',
                        'attribute' => null,
                    );
                    $eventData = array(
                        'old_value' => $originalUser['uname'],
                    );
                    $updateEvent = new Zikula_Event('user.account.update', $updatedUserObj, $eventArgs, $eventData);
                    $this->eventManager->notify($updateEvent);
                }
                if ($originalUser['email'] != $user['email']) {
                    UserUtil::setVar('email', $user['email'], $originalUser['uid']);
                }
                if ($originalUser['activated'] != $user['activated']) {
                    UserUtil::setVar('activated', $user['activated'], $originalUser['uid']);
                }
                if ($originalUser['theme'] != $user['theme']) {
                    UserUtil::setVar('theme', $user['theme'], $originalUser['uid']);
                }
                if ($formData->getField('setpass')->getData()) {
                    UserUtil::setPassword($user['pass'], $originalUser['uid']);
                    UserUtil::setVar('passreminder', $user['passreminder'], $originalUser['uid']);
                }

                $user = UserUtil::getVars($user['uid'], true);

                // TODO - This all needs to move to a Groups module hook.
                if (isset($accessPermissions)) {
                    // Fixing a high numitems to be sure to get all groups
                    $groups = ModUtil::apiFunc('Groups', 'user', 'getAll', array('numitems' => 10000));
                    $curUserGroupMembership = ModUtil::apiFunc('Groups', 'user', 'getUserGroups', array('uid' => $user['uid']));

                    foreach ($groups as $group) {
                        if (in_array($group['gid'], $accessPermissions)) {
                            // Check if the user is already in the group
                            $userIsMember = false;
                            if ($curUserGroupMembership) {
                                foreach ($curUserGroupMembership as $alreadyMemberOf) {
                                    if ($group['gid'] == $alreadyMemberOf['gid']) {
                                        $userIsMember = true;
                                        break;
                                    }
                                }
                            }
                            if ($userIsMember == false) {
                                // User is not in this group
                                ModUtil::apiFunc('Groups', 'admin', 'addUser', array(
                                    'gid' => $group['gid'],
                                    'uid' => $user['uid']
                                ));
                                $curUserGroupMembership[] = $group;
                            }
                        } else {
开发者ID:projectesIF,项目名称:Sirius,代码行数:67,代码来源:Admin.php

示例2: applyCsvValues

 public function  applyCsvValues($args){
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('IWusers::', '::', ACCESS_DELETE));
     $update = isset($args['update'])?$args['update']:null;
     $insert = isset($args['insert'])?$args['insert']:null;
     
     // Upate users table with new values
     if (!(DBUtil::updateObjectArray($update, 'users', 'uid')))
             LogUtil::registerError($this->__('Error! Update attempt failed.'));
     // Update IWusers table
     foreach ($update as &$user){
         if (DBUtil::updateObject($user, 'IWusers', "iw_uid =".$user['uid']))
             $user['action'] = 'm'; // modified //$this->__('Update');
         else 
             $user['error']= $user['uname']." - ".$this->__('Error! Update attempt failed.'). " ";
     }
     if (count($insert)){
         // Create new users in users table
         if (!(DBUtil::InsertObjectArray($insert, 'users', 'uid')))
             LogUtil::registerError($this->__('Error! New user creation attempt failed.'));
         // Create new users in IWusers table
         if (!(DBUtil::InsertObjectArray($insert, 'IWusers')))
             LogUtil::registerError($this->__('Error! New user creation attempt failed.'));
     }
     // Join update and insert arrays and process 
     $allChanges = array_merge($update, $insert);
    
     foreach ($allChanges as &$user){
         // Process "in" and "out" groups information
         ModUtil::apiFunc($this->name, 'admin', 'updateUserGroups', $user);
         // Set user pass
         if (isset($user['password']) && ($user['password']!="")) {
             // Validate pass length and pass <> uname or new_uname
             if (userUtil::validatePassword($user['password'])) {
                 UserUtil::setPassword($user['password'], $user['uid']);
             } else {
                 // Not a valid password -> error
                 $result['error'][$user['uid']] = $user;
                 $user['error'].=  $this->__('Password does not meet the minimum criteria.')." ";                    
             }
         }        
         // Force user change password?
         if ($forcechgpass) {
             switch ($user['forcechgpass']) {
                 case 1:
                     UserUtil::setVar('_Users_mustChangePassword', 1, $user['uid']);
                     break;
                 case 0;
                     UserUtil::delVar('_Users_mustChangePassword', $user['uid']);
                     break;
             }
         }
         // Change uname
         if (isset($user['new_uname']) && ($user['new_uname']!= "") && (!is_null($user['uid']))) {
             // search repeated uname/new_uname
             if (!(UserUtil::getIdFromName($user['new_uname']))) { 
                 // new_uname not exists proceed with uname change
                 $object['uname'] = $user['new_uname'];
                 //$object['uid'] = $user['uid'];
                 DBUtil::updateObject($object, 'users', "uid=".$user['uid']);
                 //UserUtil::setPassword($user['pass'], $user['uid']);
             } else {
                  $user['error'].=  $this->__f('Duplicated username: %s.', $user['new_uname']);
             }    
         }       
     }
     return $allChanges;
 }
开发者ID:projectesIF,项目名称:Sirius,代码行数:67,代码来源:Admin.php

示例3: addeditUser


//.........这里部分代码省略.........
     $user['zk']['uid'] = FormUtil::getPassedValue('uid', null, 'POST');
     //Comprovem si es passa una uid (per editar) o no (i s'ha de crear un nou usuari)
     if (!empty($user['zk']['uid'])) {
         //Comprovem que aquest usuari eixisteixi i es pugui editar (és a dir, que sigui del grup d'usuaris del catàleg)
         $grupCat = ModUtil::apiFunc('Cataleg', 'admin', 'getgrupsZikula');
         $catUsersList = UserUtil::getUsersForGroup($grupCat['Sirius']);
         if (!in_array($user['zk']['uid'], $catUsersList)) {
             LogUtil::registerError($this->__('No existeix cap usuari del catàleg amb l\'identificador indicat.'));
             return system::redirect(ModUtil::url('Cataleg', 'admin', 'usersgest'));
         }
         $user['iw']['uid'] = $user['zk']['uid'];
         $user['iw']['suid'] = $user['zk']['uid'];
         $r = 'edit';
     }
     $user['zk']['uname'] = FormUtil::getPassedValue('uname', null, 'POST');
     //Comprovem que no existeix cap usuari amb aquest uname
     if (!empty($user['zk']['uid'])) {
         $where = "uname = '" . $user['zk']['uname'] . "' AND uid != " . $user['zk']['uid'];
     } else {
         $where = "uname = '" . $user['zk']['uname'] . "'";
     }
     $uname = UserUtil::getUsers($where);
     if ($uname) {
         LogUtil::registerError($this->__('El nom d\'usuari triat ja existeix.'));
         return system::redirect(ModUtil::url('Cataleg', 'admin', 'usersgest'));
     }
     $user['zk']['email'] = FormUtil::getPassedValue('email', null, 'POST');
     $user['iw']['nom'] = FormUtil::getPassedValue('iw_nom', null, 'POST');
     $user['iw']['cognom1'] = FormUtil::getPassedValue('iw_cognom1', null, 'POST');
     $user['iw']['cognom2'] = FormUtil::getPassedValue('iw_cognom2', null, 'POST');
     $user['gr'] = FormUtil::getPassedValue('groups', null, 'POST');
     
     $prev_pass = FormUtil::getPassedValue('prev_pass', 0, 'POST');
     $setpass = FormUtil::getPassedValue('setpass', 0, 'POST');
     if ($setpass == 1) {
         $password = FormUtil::getPassedValue('password', null, 'POST');
         $changeme = FormUtil::getPassedValue('changeme', 0, 'POST');
     } else {
         $password = null;
     }
     $setcode = FormUtil::getPassedValue('setcode', 0, 'POST');
     if ($setcode == 1) $iwcode = FormUtil::getPassedValue('iwcode_s', null, 'POST');
     if ($setcode == 2) $iwcode = FormUtil::getPassedValue('iwcode_m', null, 'POST');
     if ($iwcode) {
         $user['iw']['code'] = $iwcode;
     } elseif ($r == 'edit'){
         $iwcode = DBUtil::selectField('IWusers', 'code', 'iw_uid='.$user['zk']['uid']);
     }
     if ($iwcode) {
         $gtafInfo = ModUtil::apiFunc('Cataleg','admin','getGtafEntity',$iwcode);
         $grupCat = ModUtil::apiFunc('Cataleg', 'admin', 'getgrupsZikula');
         if (isset($grupCat[$gtafInfo['entity']['tipus']])) $user['gr'][] = $grupCat[$gtafInfo['entity']['tipus']];
     }
     $insertUserId = ModUtil::apifunc('Cataleg', 'admin', 'saveUser', $user);
     if ($insertUserId) {
         if ($r == 'edit') {
             LogUtil::registerStatus($this->__('L\'usuari s\'ha editat correctament.'));
         } else {
             LogUtil::registerStatus($this->__('L\'usuari s\'ha creat correctament.'));
         }
     } else {
         LogUtil::registerError($this->__('No s\'ha pogut desar l\'usuari.'));
         return system::redirect(ModUtil::url('Cataleg', 'admin', 'usersgest'));
     }
     //Si es tria 'buidar' la contrasenya, aquesta opció mana sobre el canvi i forçar el canvi
     if ($setpass == 2) {
         $reg = array('pass' => '');
         if (DBUtil::updateObject($reg,'users','uid ='. $insertUserId)) {
             UserUtil::setVar('', $passreminder, $insertUserId);
             LogUtil::registerStatus($this->__('L\'usuari haurà de validar-se per LDAP'));
         }
     }
     // Segon pas: desem el possible canvi de contrasenya
     if ($password) {
         $rpassword = FormUtil::getPassedValue('rpassword', null, 'POST');
         $passreminder = $this->__('Constasenya establerta des de l\'administració.');
         $passwordErrors = ModUtil::apiFunc('Users', 'registration', 'getPasswordErrors', array(
                     'uname' => $user['zk']['uname'],
                     'pass' => $password,
                     'passagain' => $rpassword,
                     'passreminder' => $passreminder
         ));
         if (empty($passwordErrors)) {
             if (UserUtil::setPassword($password, $insertUserId)) {
                 UserUtil::setVar('passreminder', $passreminder, $insertUserId);
                 LogUtil::registerStatus($this->__('S\'ha desat la contrasenya.'));
             }
         } else {
             LogUtil::registerError($this->__('No s\'ha desat la contrasenya.'));
             LogUtil::registerError($passwordErrors['pass']);
         }
     }
     // Tercer pas: establim la variable que controla el forçar el canvi de contrasenya
     if ($setpass == 1 && ($prev_pass || $password)) {
         UserUtil::setVar('_Users_mustChangePassword', $changeme, $insertUserId);
         if ($changeme == 1)
             LogUtil::registerStatus($this->__('L\'usuari haurà de canviar la contrasenya en la propera validació.'));
     }
     return system::redirect(ModUtil::url('Cataleg', 'admin', 'usersgest'));
 }
开发者ID:projectesIF,项目名称:Sirius,代码行数:101,代码来源:Admin.php

示例4: checkPassword


//.........这里部分代码省略.........
        $uid = ModUtil::apiFunc($this->name, 'Authentication', 'getUidForAuthenticationInfo', $getUidArgs, 'Zikula_Api_AbstractAuthentication');

        if ($uid) {
            if (!isset($authenticationInfo['pass']) || !is_string($authenticationInfo['pass'])
                    || empty($authenticationInfo['pass'])) {
                // The user did not specify a password, or the one specified is invalid.
                throw new Zikula_Exception_Fatal($this->__('Error! A password must be provided.'));
            }

            // For a custom authenticationModule, we'd map the authenticationInfo to a uid above, and then execute the custom
            // authentication process here. On success the uid would be returned, otherwise false is returned. Note that
            // any "log in" into the Zikula site is not done here. This is simply verification that the authenticationInfo,
            // including the password, is valid as a unit.

            $userObj = UserUtil::getVars($uid, true);
            if (!$userObj) {
                // Must be a registration. Acting as an authenticationModule, we should not care at this point about the user's
                // account status. We will deal with the account status in a moment.
                $userObj = UserUtil::getVars($uid, true, '', true);

                if (!$userObj) {
                    // Neither an account nor a pending registration request. This should really not happen since we have a uid.
                    throw new Zikula_Exception_Fatal($this->__f('A user id was located, but the user account record could not be retrieved in a call to %1$s.', array(__METHOD__)));
                }
            }

            // Check for an empty password, or the special marker indicating that the account record does not
            // authenticate with a uname/password (or email/password, depending on the 'loginviaoption' setting) from
            // the Users module. An empty password can be created when an administrator creates a user registration
            // record pending e-mail verification and does not set a password for the user (the user will set it
            // upon verifying his email address). The special marker indicating that the account does not authenticate
            // with the Users module is used when a user registers a new account with the system using an authentication
            // method other than uname/pass or email/pass. In both cases, authentication automatically fails.
            if (!empty($userObj['pass']) && ($userObj['pass'] != Users_Constant::PWD_NO_USERS_AUTHENTICATION)) {
                // The following check for non-salted passwords and the old 'hash_method' field is to allow the admin to log in
                // during an upgrade from 1.2.
                // *** IMPORTANT ***
                // This needs to be kept for any version that allows an upgrade from Zikula 1.2.X.
                $methodSaltDelimPosition = strpos($userObj['pass'], Users_Constant::SALT_DELIM);
                $saltPassDelimPosition = ($methodSaltDelimPosition === false) ? false : strpos($userObj['pass'], Users_Constant::SALT_DELIM, ($methodSaltDelimPosition + 1));
                if ($saltPassDelimPosition === false) {
                    // Old style unsalted password with hash_method in separate field
                    // If this release version of Zikula Users Module allows upgrade from 1.2.X, then this part must be
                    // kept. If this release version of Zikula Users Module DOES NOT support upgrade from 1.2.X then this
                    // is the part that can go away.
                    if (!isset($userObj['hash_method'])) {
                        // Something is horribly wrong. The password on the user account record does not look like the
                        // new style of hashing, and yet the old-style hash method field is nowhere to be found.
                        throw new Zikula_Exception_Fatal($this->__('Invalid account password state.'));
                    }
                    $currentPasswordHashed = $userObj['hash_method'] . '$$' . $userObj['pass'];
                } else {
                    // New style salted password including hash method code.
                    // If this release version of Zikula Users module does not allow upgrade from 1.2.X, then this
                    // is the part to keep.
                    $currentPasswordHashed = $userObj['pass'];
                }
                // *** IMPORTANT ***
                // End of old-style versus new-style hashing handling. When the possiblity to upgrade from 1.2.X is
                // removed from the released version of Zikula Users Module, then delete this section, and replace
                // $currentPasswordHashed with $userObj['pass'] in the call to passwordsMatch below.

                if (UserUtil::passwordsMatch($authenticationInfo['pass'], $currentPasswordHashed)) {
                    // Password in $authenticationInfo['pass'] is good at this point.

                    // *** IMPORTANT ***
                    // Again, this section is for converting old-style hashing to new-style hashing. Same as noted
                    // above applies to this section.
                    // See if we need to convert the password hashing to the new configuration.
                    if (version_compare($this->modinfo['version'], '2.0.0') >= 0) {
                        // Check stored hash matches the current system type, if not convert it--but only if the module version is sufficient.
                        // Note: this is purely specific to the Users module authentication. A custom module might do something similar if it
                        // changed the way it stored some piece of data between versions, but in general this would be uncommon.
                        list($currentPasswordHashCode, $currentPasswordSaltStr, $currentPasswordHashStr) = explode(Users_Constant::SALT_DELIM, $currentPasswordHashed);
                        $systemHashMethodCode = UserUtil::getPasswordHashMethodCode($this->getVar('hash_method', 'sha256'));
                        if (($systemHashMethodCode != $currentPasswordHashCode) || empty($currentPasswordSaltStr)) {
                            if (!UserUtil::setPassword($authenticationInfo['pass'], $uid)) {
                                LogUtil::log($this->__('Internal Error! Unable to update the user\'s password with the new hashing method and/or salt.'), 'CORE');
                            }
                        }
                    }
                    // *** IMPORTANT ***
                    // End of old-style to new-style hasing conversion.

                    // The password is good, so the password is authenticated.
                    $passwordAuthenticates = true;
                }
            }
        }

        if (!$passwordAuthenticates && !$this->request->getSession()->hasMessages(Zikula_Session::MESSAGE_ERROR)) {
            if ($authenticationMethod['method'] == 'email') {
                $this->registerError($this->__('Sorry! The e-mail address or password you entered was incorrect.'));
            } else {
                $this->registerError($this->__('Sorry! The user name or password you entered was incorrect.'));
            }
        }

        return $passwordAuthenticates;
    }
开发者ID:projectesIF,项目名称:Sirius,代码行数:101,代码来源:Authentication.php

示例5: updatePassword

    /**
     * Update the user's password.
     *
     * Parameters passed via GET:
     * --------------------------
     * None.
     *
     * Parameters passed via POST:
     * ---------------------------
     * string oldpassword        The original password.
     * string newpassword        The new password to be stored for the user.
     * string newpasswordconfirm Verification of the new password to be stored for the user.
     *
     * Parameters passed via SESSION:
     * ------------------------------
     * Namespace: Zikula_Users
     * Variable:  Users_Controller_User_updatePassword
     * Type:      array
     * Contents:  An array containing the information saved from the log-in attempt in order to re-enter it, including:
     *              'authentication_method', an array containing the selected authentication module name and method name,
     *              'authentication_info', an array containing the authentication information entered by the user,
     *              'user_obj', a user record containing the user information found during the log-in attempt,
     *              'password_errors', errors that have occurred during a previous pass through this function.
     *
     * @return bool True on success, otherwise false.
     */
    public function updatePassword()
    {
        $sessionVars = $this->request->getSession()->get('Users_Controller_User_updatePassword', null, 'Zikula_Users');
        $this->request->getSession()->del('Users_Controller_User_updatePassword', 'Zikula_Users');

        if (!$this->request->isPost()) {
            throw new Zikula_Exception_Forbidden();
        }

        $this->checkCsrfToken();

        if (isset($sessionVars) && !empty($sessionVars)) {
            $login = true;
            $userObj = $sessionVars['user_obj'];
        } else {
            $login = false;
            $userObj = UserUtil::getVars(UserUtil::getVar('uid'), true);
        }
        $uid = $userObj['uid'];

        if (!$login && !UserUtil::isLoggedIn()) {
            throw new Zikula_Exception_Forbidden();
        } elseif ($login && UserUtil::isLoggedIn()) {
            throw new Zikula_Exception_Fatal();
        }

        $passwordChanged    = false;
        $currentPassword    = $this->request->request->get('oldpassword', '');
        $newPassword        = $this->request->request->get('newpassword', '');
        $newPasswordAgain   = $this->request->request->get('newpasswordconfirm', '');
        $newPasswordReminder= $this->request->request->get('passreminder', '');
        $passwordErrors     = array();

        if (empty($currentPassword) || !UserUtil::passwordsMatch($currentPassword, $userObj['pass'])) {
            $passwordErrors['oldpass'][] = $this->__('The current password you entered is not correct. Please correct your entry and try again.');
        } else {
            $passwordErrors = ModUtil::apiFunc($this->name, 'registration', 'getPasswordErrors', array(
                'uname'         => $userObj['uname'],
                'pass'          => $newPassword,
                'passagain'     => $newPasswordAgain,
                'passreminder'  => $newPasswordReminder
            ));

            if ($login && ($currentPassword == $newPassword)) {
                $passwordErrors['reginfo_pass'][] = $this->__('Your new password cannot match your current password.');
            }
        }

        if (empty($passwordErrors)) {
            if (UserUtil::setPassword($newPassword, $uid)) {
                // no user.update event for password chagnes.

                $passwordChanged = true;

                // Clear the forced change of password flag, if it exists.
                UserUtil::delVar('_Users_mustChangePassword', $uid);

                if (!UserUtil::setVar('passreminder', $newPasswordReminder, $uid)) {
                    $this->registerError($this->__('Warning! Your new password was saved, however there was a problem saving your new password reminder.'));
                } else {
                    $this->registerStatus($this->__('Done! Saved your new password.'));
                }

                $userObj = UserUtil::getVars(UserUtil::getVar('uid'), true);
                if ($login) {
                    $sessionVars['user_obj'] = $userObj;
                    if ($sessionVars['authentication_method']['modname'] == $this->name) {
                        // The password for Users module authentication was just changed.
                        // In order to successfully log in the user, we need to change it on the authentication_info.
                        $sessionVars['authentication_info']['pass'] = $newPassword;
                    }
                }
            } else {
                throw new Zikula_Exception_Fatal($this->__('Sorry! There was a problem saving your new password.'));
//.........这里部分代码省略.........
开发者ID:projectesIF,项目名称:Sirius,代码行数:101,代码来源:User.php


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