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


PHP Gdn_PasswordHash::hashPassword方法代码示例

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


在下文中一共展示了Gdn_PasswordHash::hashPassword方法的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: passwordReset

 /**
  * Do a password reset.
  *
  * @param int $UserID
  * @param string $Password
  * @return array|false Returns the user or **false** if the user doesn't exist.
  */
 public function passwordReset($UserID, $Password)
 {
     // Encrypt the password before saving
     $PasswordHash = new Gdn_PasswordHash();
     $Password = $PasswordHash->hashPassword($Password);
     $this->SQL->update('User')->set('Password', $Password)->set('HashMethod', 'Vanilla')->where('UserID', $UserID)->put();
     $this->saveAttribute($UserID, 'PasswordResetKey', '');
     $this->saveAttribute($UserID, 'PasswordResetExpires', '');
     $this->EventArguments['UserID'] = $UserID;
     $this->fireEvent('AfterPasswordReset');
     return $this->getID($UserID);
 }
开发者ID:vanilla,项目名称:vanilla,代码行数:19,代码来源:class.usermodel.php

示例3: save

 /**
  * Generic save procedure.
  *
  * $Settings controls certain save functionality
  *
  *  SaveRoles - Save 'RoleID' field as user's roles. Default false.
  *  HashPassword - Hash the provided password on update. Default true.
  *  FixUnique - Try to resolve conflicts with unique constraints on Name and Email. Default false.
  *  ValidateEmail - Make sure the provided email addresses is formattted properly. Default true.
  *  NoConfirmEmail - Disable email confirmation. Default false.
  *
  */
 public function save($FormPostValues, $Settings = false)
 {
     // See if the user's related roles should be saved or not.
     $SaveRoles = val('SaveRoles', $Settings);
     // Define the primary key in this model's table.
     $this->defineSchema();
     // Custom Rule: This will make sure that at least one role was selected if saving roles for this user.
     if ($SaveRoles) {
         $this->Validation->addRule('OneOrMoreArrayItemRequired', 'function:ValidateOneOrMoreArrayItemRequired');
         // $this->Validation->AddValidationField('RoleID', $FormPostValues);
         $this->Validation->applyRule('RoleID', 'OneOrMoreArrayItemRequired');
     }
     // Make sure that checkbox vals are saved as the appropriate value
     if (array_key_exists('ShowEmail', $FormPostValues)) {
         $FormPostValues['ShowEmail'] = ForceBool($FormPostValues['ShowEmail'], '0', '1', '0');
     }
     if (array_key_exists('Banned', $FormPostValues)) {
         $FormPostValues['Banned'] = ForceBool($FormPostValues['Banned'], '0', '1', '0');
     }
     if (array_key_exists('Confirmed', $FormPostValues)) {
         $FormPostValues['Confirmed'] = ForceBool($FormPostValues['Confirmed'], '0', '1', '0');
     }
     unset($FormPostValues['Admin']);
     // Validate the form posted values
     if (array_key_exists('Gender', $FormPostValues)) {
         $FormPostValues['Gender'] = self::fixGender($FormPostValues['Gender']);
     }
     if (array_key_exists('DateOfBirth', $FormPostValues) && $FormPostValues['DateOfBirth'] == '0-00-00') {
         $FormPostValues['DateOfBirth'] = null;
     }
     $UserID = val('UserID', $FormPostValues);
     $User = array();
     $Insert = $UserID > 0 ? false : true;
     if ($Insert) {
         $this->addInsertFields($FormPostValues);
     } else {
         $this->addUpdateFields($FormPostValues);
         $User = $this->getID($UserID, DATASET_TYPE_ARRAY);
         if (!$User) {
             $User = array();
         }
         // Block banning the superadmin or System accounts
         if (val('Admin', $User) == 2 && val('Banned', $FormPostValues)) {
             $this->Validation->addValidationResult('Banned', 'You may not ban a System user.');
         } elseif (val('Admin', $User) && val('Banned', $FormPostValues)) {
             $this->Validation->addValidationResult('Banned', 'You may not ban a user with the Admin flag set.');
         }
     }
     $this->EventArguments['FormPostValues'] = $FormPostValues;
     $this->fireEvent('BeforeSaveValidation');
     $RecordRoleChange = true;
     if ($UserID && val('FixUnique', $Settings)) {
         $UniqueValid = $this->validateUniqueFields(val('Name', $FormPostValues), val('Email', $FormPostValues), $UserID, true);
         if (!$UniqueValid['Name']) {
             unset($FormPostValues['Name']);
         }
         if (!$UniqueValid['Email']) {
             unset($FormPostValues['Email']);
         }
         $UniqueValid = true;
     } else {
         $UniqueValid = $this->validateUniqueFields(val('Name', $FormPostValues), val('Email', $FormPostValues), $UserID);
     }
     // Add & apply any extra validation rules:
     if (array_key_exists('Email', $FormPostValues) && val('ValidateEmail', $Settings, true)) {
         $this->Validation->applyRule('Email', 'Email');
     }
     if ($this->validate($FormPostValues, $Insert) && $UniqueValid) {
         $Fields = $this->Validation->validationFields();
         // All fields on the form that need to be validated (including non-schema field rules defined above)
         $RoleIDs = val('RoleID', $Fields, 0);
         $Username = val('Name', $Fields);
         $Email = val('Email', $Fields);
         $Fields = $this->Validation->schemaValidationFields();
         // Only fields that are present in the schema
         // Remove the primary key from the fields collection before saving
         $Fields = removeKeyFromArray($Fields, $this->PrimaryKey);
         if (array_key_exists('AllIPAddresses', $Fields) && is_array($Fields['AllIPAddresses'])) {
             $Fields['AllIPAddresses'] = implode(',', $Fields['AllIPAddresses']);
         }
         if (!$Insert && array_key_exists('Password', $Fields) && val('HashPassword', $Settings, true)) {
             // Encrypt the password for saving only if it won't be hashed in _Insert()
             $PasswordHash = new Gdn_PasswordHash();
             $Fields['Password'] = $PasswordHash->hashPassword($Fields['Password']);
             $Fields['HashMethod'] = 'Vanilla';
         }
         // Check for email confirmation.
         if (self::requireConfirmEmail() && !val('NoConfirmEmail', $Settings)) {
//.........这里部分代码省略.........
开发者ID:dimassrio,项目名称:vanilla,代码行数:101,代码来源:class.usermodel.php


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