当前位置: 首页>>代码示例>>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方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: PasswordReset

 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)->Where('UserID', $UserID)->Put();
     $this->SaveAttribute($UserID, 'PasswordResetKey', '');
     return $this->Get($UserID);
 }
开发者ID:TiGR,项目名称:Garden,代码行数:9,代码来源:class.usermodel.php

示例2: 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)
 {
     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()) {
             $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()))));
             } else {
                 // Check the password.
                 $PasswordHash = new Gdn_PasswordHash();
                 $Password = $this->Form->GetFormValue('Password');
                 try {
                     $PasswordChecked = $PasswordHash->CheckPassword($Password, GetValue('Password', $User), GetValue('HashMethod', $User));
                     // Rate limiting
                     Gdn::UserModel()->RateLimit($User, $PasswordChecked);
                     if ($PasswordChecked) {
                         // Update weak passwords
                         $HashMethod = GetValue('HashMethod', $User);
                         if ($PasswordHash->Weak || $HashMethod && strcasecmp($HashMethod, 'Vanilla') != 0) {
                             $Pw = $PasswordHash->HashPassword($Password);
                             Gdn::UserModel()->SetField(GetValue('UserID', $User), array('Password' => $Pw, 'HashMethod' => 'Vanilla'));
                         }
                         Gdn::Session()->Start(GetValue('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.');
                     }
                 } 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:elpum,项目名称:TgaForumBundle,代码行数:86,代码来源:class.entrycontroller.php

示例3: InsertUserTable

 public function InsertUserTable()
 {
     $UseCurrentPassword = $this->Data('UseCurrentPassword');
     if ($UseCurrentPassword) {
         $CurrentUser = $this->SQL->GetWhere('User', array('UserID' => Gdn::Session()->UserID))->FirstRow(DATASET_TYPE_ARRAY);
         $CurrentPassword = $CurrentUser['Password'];
         $CurrentHashMethod = $CurrentUser['HashMethod'];
     }
     // Delete the current user table.
     $this->SQL->Truncate('User');
     // Load the new user table.
     $UserTableInfo =& $this->Data['Tables']['User'];
     if (!$this->ImportExists('User', 'HashMethod')) {
         $this->_InsertTable('User', array('HashMethod' => $this->GetPasswordHashMethod()));
     } else {
         $this->_InsertTable('User');
     }
     $UserTableInfo['Inserted'] = TRUE;
     $AdminEmail = GetValue('OverwriteEmail', $this->Data);
     $SqlArgs = array(':Email' => $AdminEmail);
     $SqlSet = '';
     if ($UseCurrentPassword) {
         $SqlArgs[':Password'] = $CurrentPassword;
         $SqlArgs[':HashMethod'] = $CurrentHashMethod;
         $SqlSet = ', Password = :Password, HashMethod = :HashMethod';
     }
     // If doing a password reset, save out the new admin password:
     if (strcasecmp($this->GetPasswordHashMethod(), 'reset') == 0) {
         if (!isset($SqlArgs[':Password'])) {
             $PasswordHash = new Gdn_PasswordHash();
             $Hash = $PasswordHash->HashPassword(GetValue('OverwritePassword', $this->Data));
             $SqlSet .= ', Password = :Password, HashMethod = :HashMethod';
             $SqlArgs[':Password'] = $Hash;
             $SqlArgs[':HashMthod'] = 'Vanilla';
         }
         // Write it out.
         $this->Query("update :_User set Admin = 1{$SqlSet} where Email = :Email", $SqlArgs);
     } else {
         // Set the admin user flag.
         $this->Query("update :_User set Admin = 1{$SqlSet} where Email = :Email", $SqlArgs);
     }
     // Start the new session.
     $User = Gdn::UserModel()->GetByEmail(GetValue('OverwriteEmail', $this->Data));
     if (!$User) {
         $User = Gdn::UserModel()->GetByUsername(GetValue('OverwriteEmail', $this->Data));
     }
     $PasswordHash = new Gdn_PasswordHash();
     if ($this->Data('UseCurrentPassword') || $PasswordHash->CheckPassword(GetValue('OverwritePassword', $this->Data), GetValue('Password', $User), GetValue('HashMethod', $User))) {
         Gdn::Session()->Start(GetValue('UserID', $User), TRUE);
     }
     return TRUE;
 }
开发者ID:elpum,项目名称:TgaForumBundle,代码行数:52,代码来源:class.importmodel.php

示例4: insertUserTable

 /**
  *
  *
  * @return bool
  */
 public function insertUserTable()
 {
     $CurrentUser = $this->SQL->getWhere('User', array('UserID' => Gdn::session()->UserID))->firstRow(DATASET_TYPE_ARRAY);
     $CurrentPassword = $CurrentUser['Password'];
     $CurrentHashMethod = $CurrentUser['HashMethod'];
     $CurrentTransientKey = gdn::session()->transientKey();
     // Delete the current user table.
     $this->SQL->Truncate('User');
     // Load the new user table.
     $UserTableInfo =& $this->Data['Tables']['User'];
     if (!$this->importExists('User', 'HashMethod')) {
         $this->_InsertTable('User', array('HashMethod' => $this->GetPasswordHashMethod()));
     } else {
         $this->_InsertTable('User');
     }
     $UserTableInfo['Inserted'] = true;
     $AdminEmail = val('OverwriteEmail', $this->Data);
     $SqlArgs = array(':Email' => $AdminEmail);
     $SqlSet = '';
     $SqlArgs[':Password'] = $CurrentPassword;
     $SqlArgs[':HashMethod'] = $CurrentHashMethod;
     $SqlSet = ', Password = :Password, HashMethod = :HashMethod';
     // If doing a password reset, save out the new admin password:
     if (strcasecmp($this->GetPasswordHashMethod(), 'reset') == 0) {
         if (!isset($SqlArgs[':Password'])) {
             $PasswordHash = new Gdn_PasswordHash();
             $Hash = $PasswordHash->HashPassword(val('OverwritePassword', $this->Data));
             $SqlSet .= ', Password = :Password, HashMethod = :HashMethod';
             $SqlArgs[':Password'] = $Hash;
             $SqlArgs[':HashMthod'] = 'Vanilla';
         }
         // Write it out.
         $this->query("update :_User set Admin = 1{$SqlSet} where Email = :Email", $SqlArgs);
     } else {
         // Set the admin user flag.
         $this->query("update :_User set Admin = 1{$SqlSet} where Email = :Email", $SqlArgs);
     }
     // Start the new session.
     $User = Gdn::userModel()->GetByEmail(val('OverwriteEmail', $this->Data));
     if (!$User) {
         $User = Gdn::userModel()->GetByUsername(val('OverwriteEmail', $this->Data));
     }
     Gdn::session()->start(val('UserID', $User), true);
     gdn::session()->transientKey($CurrentTransientKey);
     return true;
 }
开发者ID:R-J,项目名称:vanilla,代码行数:51,代码来源:class.importmodel.php

示例5: PasswordReset

 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->EventArguments['UserID'] = $UserID;
     $this->FireEvent('AfterPasswordReset');
     return $this->GetID($UserID);
 }
开发者ID:statico,项目名称:openshift-origin-vanillaforums,代码行数:11,代码来源:class.usermodel.php

示例6: InsertUserTable

 public function InsertUserTable()
 {
     // Delete the current user table.
     $this->Query('truncate table :_User');
     // Load the new user table.
     $UserTableInfo =& $this->Data['Tables']['User'];
     $this->_InsertTable('User', array('HashMethod' => $this->GetPasswordHashMethod()));
     $UserTableInfo['Inserted'] = TRUE;
     // Set the admin user flag.
     $AdminEmail = GetValue('OverwriteEmail', $this->Data);
     $this->Query('update :_User set Admin = 1 where Email = :Email', array(':Email' => $AdminEmail));
     // If doing a password reset, save out the new admin password:
     if (strcasecmp($this->GetPasswordHashMethod(), 'reset') == 0) {
         $PasswordHash = new Gdn_PasswordHash();
         $Hash = $PasswordHash->HashPassword(GetValue('OverwritePassword', $this->Data));
         // Write it out.
         $AdminEmail = GetValue('OverwriteEmail', $this->Data);
         $this->Query('update :_User set Admin = 1, Password = :Hash, HashMethod = "vanilla" where Email = :Email', array(':Hash' => $Hash, ':Email' => $AdminEmail));
     } else {
         // Set the admin user flag.
         $AdminEmail = GetValue('OverwriteEmail', $this->Data);
         $this->Query('update :_User set Admin = 1 where Email = :Email', array(':Email' => $AdminEmail));
     }
     // Authenticate the admin user as the current user.
     $PasswordAuth = Gdn::Authenticator()->AuthenticateWith('password');
     //$PasswordAuth->FetchData($PasswordAuth, array('Email' => GetValue('OverwriteEmail', $this->Data), 'Password' => GetValue('OverwritePassword', $this->Data)));
     $PasswordAuth->Authenticate(GetValue('OverwriteEmail', $this->Data), GetValue('OverwritePassword', $this->Data));
     Gdn::Session()->Start();
     return TRUE;
 }
开发者ID:kennyma,项目名称:Garden,代码行数:30,代码来源:class.importmodel.php

示例7: InsertUserTable

 public function InsertUserTable()
 {
     $UserCurrentPassword = $this->Data('UseCurrentPassword');
     // Delete the current user table.
     $this->Query('truncate table :_User');
     // Load the new user table.
     $UserTableInfo =& $this->Data['Tables']['User'];
     $this->_InsertTable('User', array('HashMethod' => $this->GetPasswordHashMethod()));
     $UserTableInfo['Inserted'] = TRUE;
     $AdminEmail = GetValue('OverwriteEmail', $this->Data);
     $SqlArgs = array(':Email' => $AdminEmail);
     $SqlSet = '';
     if ($UserCurrentPassword) {
         $SqlArgs[':Password'] = Gdn::Session()->User->Password;
         $SqlArgs[':HashMethod'] = Gdn::Session()->User->HashMethod;
         $SqlSet = ', Password = :Password, HashMethod = :HashMethod';
     }
     // If doing a password reset, save out the new admin password:
     if (strcasecmp($this->GetPasswordHashMethod(), 'reset') == 0) {
         if (!isset($SqlArgs[':Password'])) {
             $PasswordHash = new Gdn_PasswordHash();
             $Hash = $PasswordHash->HashPassword(GetValue('OverwritePassword', $this->Data));
             $SqlSet .= ', Password = :Password, HashMethod = :HashMethod';
             $SqlArgs[':Password'] = $Hash;
             $SqlArgs[':HashMthod'] = 'Vanilla';
         }
         // Write it out.
         $this->Query("update :_User set Admin = 1{$SqlSet} where Email = :Email", $SqlArgs);
     } else {
         // Set the admin user flag.
         $this->Query("update :_User set Admin = 1{$SqlSet} where Email = :Email", $SqlArgs);
     }
     // Authenticate the admin user as the current user.
     $PasswordAuth = Gdn::Authenticator()->AuthenticateWith('password');
     //$PasswordAuth->FetchData($PasswordAuth, array('Email' => GetValue('OverwriteEmail', $this->Data), 'Password' => GetValue('OverwritePassword', $this->Data)));
     $PasswordAuth->Authenticate(GetValue('OverwriteEmail', $this->Data), GetValue('OverwritePassword', $this->Data));
     Gdn::Session()->Start();
     return TRUE;
 }
开发者ID:tautomers,项目名称:knoopvszombies,代码行数:39,代码来源:class.importmodel.php


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