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


PHP Application_Model_User::setPassword_salt方法代码示例

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


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

示例1: indexAction

 public function indexAction()
 {
     if (Zend_Auth::getInstance()->hasIdentity()) {
         return $this->_redirect('/');
     }
     // process the form
     $form = new Application_Form_Register();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             if ($form->getValue('password') == $form->getValue('password_confirm')) {
                 /**
                  * Check if a user with the given username or email already
                  * exists
                  */
                 $user_mapper = new Application_Model_UserMapper();
                 $user = $user_mapper->findByUsername($form->getValue('username'));
                 $email = $user_mapper->findByEmail($form->getValue('email'));
                 if (!$user && !$email) {
                     $values = $form->getValues();
                     $user_mapper = new Application_Model_UserMapper();
                     $user = new Application_Model_User($values);
                     // Hash the password with a random salt
                     $user->setPassword_salt(mcrypt_create_iv(64));
                     $user->setPassword_hash(hash('sha256', $user->getPassword_salt() . $form->getValue('password')));
                     $user->setActive(0);
                     // Insert the account into the database
                     $user_mapper->save($user);
                     $user = $user_mapper->findByUsername($user->getUsername());
                     if ($user) {
                         $user = $user[0];
                         // prompt the user to activate the account
                         $this->_helper->FlashMessenger('Successful Registration');
                         return $this->_redirect('/registration/confirm/id/' . $user->getId());
                     }
                 } else {
                     if ($user) {
                         print "A user with this user name already exists.";
                     }
                     if ($email) {
                         print "A user with this email already exists.";
                     }
                 }
             } else {
                 print "The password was not confirmed.";
             }
         } else {
             print 'Invalid form';
         }
     }
     $this->view->form = $form;
 }
开发者ID:alclin,项目名称:zend_framework,代码行数:51,代码来源:RegistrationController.php

示例2: editAction

 public function editAction()
 {
     if (!Zend_Auth::getInstance()->hasIdentity()) {
         return $this->_redirect('/');
     }
     $user = new Zend_Session_Namespace('user');
     // process the form
     $form = new Application_Form_UserEdit();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             /**
              * Because some fields are excluded from the form, they will be
              * set manually
              */
             $id = $user->user['id'];
             $username = $user->user['username'];
             $password_salt = $user->user['password_salt'];
             $password_hash = $user->user['password_hash'];
             if ($form->getValue('password') == $form->getValue('password_confirm')) {
                 /**
                  * Check if the user changed the email to one that is
                  * already in use
                  */
                 $user_mapper = new Application_Model_UserMapper();
                 $email = $user_mapper->findByEmail($form->getValue('email'));
                 $duplicate = false;
                 if ($email) {
                     $email = $email[0];
                     if ($id != $email->getId()) {
                         $duplicate = true;
                     }
                 }
                 if (!$duplicate) {
                     // update the user
                     $values = $form->getValues();
                     $user_mapper = new Application_Model_UserMapper();
                     $user = new Application_Model_User($values);
                     $user->setId($id);
                     $user->setUsername($username);
                     $user->setPassword_salt($password_salt);
                     $user->setPassword_hash($password_hash);
                     $user->setActive(1);
                     $user_mapper->save($user);
                     // update the session
                     $session = new Zend_Session_Namespace('user');
                     $session->user = $user->get_array();
                     $this->_helper->FlashMessenger('Successful Update');
                     return $this->_redirect('/user');
                 } else {
                     print "A user with this email already exists.";
                 }
             } else {
                 print "The password was not confirmed.";
             }
         } else {
             print 'Invalid form';
         }
     }
     // populate the form with the user's information
     $elements = $form->getElements();
     unset($elements['submit']);
     foreach ($elements as $key => $row) {
         $form->{$key}->setValue($user->user[$key]);
     }
     $this->view->form = $form;
 }
开发者ID:alclin,项目名称:zend_framework,代码行数:66,代码来源:UserController.php


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