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


PHP Gdn_PasswordHash::checkPassword方法代码示例

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


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

示例1: signIn

 /**
  * Signin process that multiple authentication methods.
  *
  * @access public
  * @since 2.0.0
  * @author Tim Gunter
  *
  * @param string $Method
  * @param array $Arg1
  * @return string Rendered XHTML template.
  */
 public function signIn($Method = false, $Arg1 = false)
 {
     if (!$this->Request->isPostBack()) {
         $this->checkOverride('SignIn', $this->target());
     }
     Gdn::session()->ensureTransientKey();
     $this->addJsFile('entry.js');
     $this->setData('Title', t('Sign In'));
     $this->Form->addHidden('Target', $this->target());
     $this->Form->addHidden('ClientHour', date('Y-m-d H:00'));
     // Use the server's current hour as a default.
     // Additional signin methods are set up with plugins.
     $Methods = array();
     $this->setData('Methods', $Methods);
     $this->setData('FormUrl', url('entry/signin'));
     $this->fireEvent('SignIn');
     if ($this->Form->isPostBack()) {
         $this->Form->validateRule('Email', 'ValidateRequired', sprintf(t('%s is required.'), t(UserModel::signinLabelCode())));
         $this->Form->validateRule('Password', 'ValidateRequired');
         if (!$this->Request->isAuthenticatedPostBack() && !c('Garden.Embed.Allow')) {
             $this->Form->addError('Please try again.');
         }
         // Check the user.
         if ($this->Form->errorCount() == 0) {
             $Email = $this->Form->getFormValue('Email');
             $User = Gdn::userModel()->GetByEmail($Email);
             if (!$User) {
                 $User = Gdn::userModel()->GetByUsername($Email);
             }
             if (!$User) {
                 $this->Form->addError('@' . sprintf(t('User not found.'), strtolower(t(UserModel::SigninLabelCode()))));
                 Logger::event('signin_failure', Logger::INFO, '{signin} failed to sign in. User not found.', array('signin' => $Email));
             } else {
                 // Check the password.
                 $PasswordHash = new Gdn_PasswordHash();
                 $Password = $this->Form->getFormValue('Password');
                 try {
                     $PasswordChecked = $PasswordHash->checkPassword($Password, val('Password', $User), val('HashMethod', $User));
                     // Rate limiting
                     Gdn::userModel()->rateLimit($User, $PasswordChecked);
                     if ($PasswordChecked) {
                         // Update weak passwords
                         $HashMethod = val('HashMethod', $User);
                         if ($PasswordHash->Weak || $HashMethod && strcasecmp($HashMethod, 'Vanilla') != 0) {
                             $Pw = $PasswordHash->hashPassword($Password);
                             Gdn::userModel()->setField(val('UserID', $User), array('Password' => $Pw, 'HashMethod' => 'Vanilla'));
                         }
                         Gdn::session()->start(val('UserID', $User), true, (bool) $this->Form->getFormValue('RememberMe'));
                         if (!Gdn::session()->checkPermission('Garden.SignIn.Allow')) {
                             $this->Form->addError('ErrorPermission');
                             Gdn::session()->end();
                         } else {
                             $ClientHour = $this->Form->getFormValue('ClientHour');
                             $HourOffset = Gdn::session()->User->HourOffset;
                             if (is_numeric($ClientHour) && $ClientHour >= 0 && $ClientHour < 24) {
                                 $HourOffset = $ClientHour - date('G', time());
                             }
                             if ($HourOffset != Gdn::session()->User->HourOffset) {
                                 Gdn::userModel()->setProperty(Gdn::session()->UserID, 'HourOffset', $HourOffset);
                             }
                             Gdn::userModel()->fireEvent('AfterSignIn');
                             $this->_setRedirect();
                         }
                     } else {
                         $this->Form->addError('Invalid password.');
                         Logger::event('signin_failure', Logger::WARNING, '{username} failed to sign in.  Invalid password.', array('InsertName' => $User->Name));
                     }
                 } catch (Gdn_UserException $Ex) {
                     $this->Form->addError($Ex);
                 }
             }
         }
     } else {
         if ($Target = $this->Request->get('Target')) {
             $this->Form->addHidden('Target', $Target);
         }
         $this->Form->setValue('RememberMe', true);
     }
     return $this->render();
 }
开发者ID:korelstar,项目名称:vanilla,代码行数:91,代码来源:class.entrycontroller.php

示例2: validateCredentials

 /**
  * Validate User Credential.
  *
  * Fetches a user row by email (or name) and compare the password.
  * If the password was not stored as a blowfish hash, the password will be saved again.
  * Return the user's id, admin status and attributes.
  *
  * @param string $Email
  * @param string $Password
  * @return object|false Returns the user matching the credentials or **false** if the user doesn't validate.
  */
 public function validateCredentials($Email = '', $ID = 0, $Password)
 {
     $this->EventArguments['Credentials'] = ['Email' => $Email, 'ID' => $ID, 'Password' => $Password];
     $this->fireEvent('BeforeValidateCredentials');
     if (!$Email && !$ID) {
         throw new Exception('The email or id is required');
     }
     try {
         $this->SQL->select('UserID, Name, Attributes, Admin, Password, HashMethod, Deleted, Banned')->from('User');
         if ($ID) {
             $this->SQL->where('UserID', $ID);
         } else {
             if (strpos($Email, '@') > 0) {
                 $this->SQL->where('Email', $Email);
             } else {
                 $this->SQL->where('Name', $Email);
             }
         }
         $DataSet = $this->SQL->get();
     } catch (Exception $Ex) {
         $this->SQL->reset();
         // Try getting the user information without the new fields.
         $this->SQL->select('UserID, Name, Attributes, Admin, Password')->from('User');
         if ($ID) {
             $this->SQL->where('UserID', $ID);
         } else {
             if (strpos($Email, '@') > 0) {
                 $this->SQL->where('Email', $Email);
             } else {
                 $this->SQL->where('Name', $Email);
             }
         }
         $DataSet = $this->SQL->get();
     }
     if ($DataSet->numRows() < 1) {
         return false;
     }
     $UserData = $DataSet->firstRow();
     // Check for a deleted user.
     if (val('Deleted', $UserData)) {
         return false;
     }
     $PasswordHash = new Gdn_PasswordHash();
     $HashMethod = val('HashMethod', $UserData);
     if (!$PasswordHash->checkPassword($Password, $UserData->Password, $HashMethod, $UserData->Name)) {
         return false;
     }
     if ($PasswordHash->Weak || $HashMethod && strcasecmp($HashMethod, 'Vanilla') != 0) {
         $Pw = $PasswordHash->hashPassword($Password);
         $this->SQL->update('User')->set('Password', $Pw)->set('HashMethod', 'Vanilla')->where('UserID', $UserData->UserID)->put();
     }
     $UserData->Attributes = dbdecode($UserData->Attributes);
     return $UserData;
 }
开发者ID:vanilla,项目名称:vanilla,代码行数:65,代码来源:class.usermodel.php

示例3: authenticate

 /**
  *
  *
  * @throws Exception
  * @throws Gdn_UserException
  */
 public function authenticate()
 {
     if (!$this->Request->isPostBack()) {
         throw forbiddenException($this->Request->requestMethod());
     }
     $Args = array_change_key_case($this->Form->formValues());
     $UserModel = new UserModel();
     // Look up the user.
     $User = null;
     if ($Email = val('email', $Args)) {
         $User = $UserModel->getByEmail($Email);
     } elseif ($Name = val('name', $Args)) {
         $User = $UserModel->getByUsername($Name);
     } else {
         throw new Gdn_UserException("One of the following parameters required: Email, Name.", 400);
     }
     if (!$User) {
         throw notFoundException('User');
     }
     // Check the password.
     $PasswordHash = new Gdn_PasswordHash();
     $Password = val('password', $Args);
     try {
         $PasswordChecked = $PasswordHash->checkPassword($Password, val('Password', $User), val('HashMethod', $User));
         // Rate limiting
         Gdn::userModel()->rateLimit($User, $PasswordChecked);
         if ($PasswordChecked) {
             $this->setData('User', arrayTranslate((array) $User, array('UserID', 'Name', 'Email', 'PhotoUrl')));
             if (val('session', $Args)) {
                 Gdn::session()->start($this->data('User.UserID'));
                 $this->setData('Cookie', array(c('Garden.Cookie.Name') => $_COOKIE[c('Garden.Cookie.Name')]));
             }
         } else {
             throw new Exception(t('Invalid password.'), 401);
             // Can't be a user exception.
         }
     } catch (Gdn_UserException $Ex) {
         $this->Form->addError($Ex);
     }
     $this->render();
 }
开发者ID:vanilla,项目名称:vanilla,代码行数:47,代码来源:class.usercontroller.php


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