本文整理汇总了PHP中App::hash方法的典型用法代码示例。如果您正苦于以下问题:PHP App::hash方法的具体用法?PHP App::hash怎么用?PHP App::hash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App
的用法示例。
在下文中一共展示了App::hash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onAfterInitialise
public function onAfterInitialise()
{
// No remember me for admin
if (!App::isSite()) {
return;
}
if (User::isGuest()) {
$hash = App::hash('JLOGIN_REMEMBER');
if ($str = Request::getString($hash, '', 'cookie', 1 | 2)) {
$credentials = array();
$goodCookie = true;
$filter = JFilterInput::getInstance();
// Create the encryption key, apply extra hardening using the user agent string.
// Since we're decoding, no UA validity check is required.
$privateKey = App::hash(@$_SERVER['HTTP_USER_AGENT']);
$crypt = new \Hubzero\Encryption\Encrypter(new \Hubzero\Encryption\Cipher\Simple(), new \Hubzero\Encryption\Key('simple', $privateKey, $privateKey));
try {
$str = $crypt->decrypt($str);
if (!is_string($str)) {
throw new Exception('Decoded cookie is not a string.');
}
$cookieData = json_decode($str);
if (null === $cookieData) {
throw new Exception('JSON could not be docoded.');
}
if (!is_object($cookieData)) {
throw new Exception('Decoded JSON is not an object.');
}
// json_decoded cookie could be any object structure, so make sure the
// credentials are well structured and only have user and password.
if (isset($cookieData->username) && is_string($cookieData->username)) {
$credentials['username'] = $filter->clean($cookieData->username, 'username');
} else {
throw new Exception('Malformed username.');
}
if (isset($cookieData->password) && is_string($cookieData->password)) {
$credentials['password'] = $filter->clean($cookieData->password, 'string');
} else {
throw new Exception('Malformed password.');
}
// We're only doing this for the site app, so we explicitly set the action here
$return = App::get('auth')->login($credentials, array('silent' => true, 'action' => 'core.login.site'));
if (!$return) {
throw new Exception('Log-in failed.');
}
} catch (Exception $e) {
$cookie_domain = Config::get('cookie_domain', '');
$cookie_path = Config::get('cookie_path', '/');
// Clear the remember me cookie
setcookie(App::hash('JLOGIN_REMEMBER'), false, time() - 86400, $cookie_path, $cookie_domain);
Log::warning('A remember me cookie was unset for the following reason: ' . $e->getMessage());
}
}
}
}
示例2: onUserLogout
/**
* This method should handle any logout logic and report back to the subject
*
* @param array $user Holds the user data.
* @param array $options Array holding options (client, ...).
* @return object True on success
*/
public function onUserLogout($user, $options = array())
{
if (App::isSite()) {
// Create the cookie
$hash = App::hash('plgSystemLogout');
$cookie_domain = Config::get('config.cookie_domain', '');
$cookie_path = Config::get('config.cookie_path', '/');
setcookie($hash, true, time() + 86400, $cookie_path, $cookie_domain);
}
return true;
}
示例3: eat
/**
* Retrieve a cookie
*
* @param (string) $namespace - make sure the cookie name is unique
* @return (object) $cookie data
**/
public static function eat($namespace)
{
$hash = \App::hash(\App::get('client')->name . ':' . $namespace);
$key = \App::hash('');
$crypt = new \Hubzero\Encryption\Encrypter(new \Hubzero\Encryption\Cipher\Simple(), new \Hubzero\Encryption\Key('simple', $key, $key));
if ($str = \App::get('request')->getString($hash, '', 'cookie', JREQUEST_ALLOWRAW | JREQUEST_NOTRIM)) {
$sstr = $crypt->decrypt($str);
$cookie = @unserialize($sstr);
return (object) $cookie;
}
return false;
}
示例4: createSession
public function createSession($user)
{
if (empty($user)) {
return;
}
try {
Db::begin();
$user->last_login = Db::now();
$user->store();
$session = Orm::collection('Session')->load();
$session->user = $user;
$session->token = App::hash(uniqid(rand(), true));
$session->store();
Db::commit();
} catch (Exception $e) {
Db::rollback();
throw $e;
}
return $session->token;
}
示例5: sendtoken
/**
* Send out local password set confirmation token
*
* @return void - redirect to confirm token view
*/
private function sendtoken()
{
// Import helpers/classes
jimport('joomla.mail.helper');
jimport('joomla.user.helper');
// Make sure they're logged in
if ($this->user->get('guest')) {
App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode(Route::url('index.php?option=' . $this->option . '&task=myaccount&active=account&action=sendtoken'))), Lang::txt('You must be a logged in to access this area.'), 'warning');
return;
}
// Make sure this is an auth link account (i.e. no password set)
$hzup = \Hubzero\User\Password::getInstance($this->member->get('uidNumber'));
if (!empty($hzup->passhash)) {
App::abort(404, Lang::txt('PLG_MEMBERS_ACCOUNT_NOT_LINKED_ACCOUNT'));
return;
}
// Generate a new random token and hash it
$token = App::hash(JUserHelper::genRandomPassword());
$salt = JUserHelper::getSalt('crypt-md5');
$hashedToken = md5($token . $salt) . ':' . $salt;
// Store the hashed token
$this->setToken($hashedToken);
// Send the email with the token
$this->sendEmail($token);
// Redirect user to confirm token view page
App::redirect(Route::url($this->member->getLink() . '&active=account&task=confirmtoken'), Lang::txt('Please check the email associated with this account (' . $this->member->get('email') . ') for your confirmation token!'), 'warning');
return;
}
示例6: defined
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* HUBzero is a registered trademark of Purdue University.
*
* @package hubzero-cms
* @author Sam Wilson <samwilson@purdue.edu>
* @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
* @license http://opensource.org/licenses/MIT MIT
*/
// no direct access
defined('_HZEXEC_') or die;
$hash = App::hash(App::get('client')->name . ':authenticator');
if (($cookie = \Hubzero\Utility\Cookie::eat('authenticator')) && !Request::getInt('reset', false)) {
$primary = $cookie->authenticator;
$user = User::getInstance($cookie->user_id);
$user_img = $cookie->user_img;
Request::setVar('primary', $primary);
}
$usersConfig = Component::params('com_members');
$primary = Request::getWord('primary', false);
// use some reflections to inspect plugins for special behavior (added for shibboleth)
$refl = array();
foreach ($authenticators as $a) {
$refl[$a['name']] = new \ReflectionClass("plgAuthentication{$a['name']}");
}
$current = Hubzero\Utility\Uri::getInstance()->toString();
$current .= strstr($current, '?') ? '&' : '?';
示例7: getFormToken
/**
* Method to determine a hash for anti-spoofing variable names
*
* @param boolean $forceNew If true, force a new token to be created
* @return string Hashed var name
*/
public static function getFormToken($forceNew = false)
{
$hash = \App::hash(\User::get('id', 0) . \App::get('session')->getToken($forceNew));
return $hash;
}
示例8: getUserByCredentials
public function getUserByCredentials($login, $password)
{
return $this->driver->getUserByCredentials($login, App::hash($password));
}
示例9: onLoginUser
/**
* This method should handle any login logic and report back to the subject
*
* @param array $user holds the user data
* @param array $options array holding options (remember, autoregister, group)
* @return boolean True on success
*/
public function onLoginUser($user, $options = array())
{
jimport('joomla.user.helper');
$xuser = User::getRoot();
// get user from session (might be tmp_user, can't fetch from db)
if ($xuser->get('guest')) {
// joomla user plugin hasn't run or something went very badly
$plugins = Plugin::byType('user');
$xuser_order = false;
$joomla_order = false;
$i = 0;
foreach ($plugins as $plugin) {
if ($plugin->name == 'xusers') {
$xuser_order = $i;
}
if ($plugin->name == 'joomla') {
$joomla_order = $i;
}
$i++;
}
if ($joomla_order === false) {
return new Exception(Lang::txt('E_JOOMLA_USER_PLUGIN_MISCONFIGURED'), 500);
}
if ($xuser_order <= $joomla_order) {
return new Exception(Lang::txt('E_HUBZERO_USER_PLUGIN_MISCONFIGURED'), 500);
}
return new Exception(Lang::txt('E_JOOMLA_USER_PLUGIN_FAILED'), 500);
}
// log login to auth log
Log::auth($xuser->get('id') . ' [' . $xuser->get('username') . '] ' . $_SERVER['REMOTE_ADDR'] . ' login');
// correct apache log data
apache_note('auth', 'login');
// Log attempt to the database
Hubzero\User\User::oneOrFail($xuser->get('id'))->logger()->auth()->save(['username' => $xuser->get('username'), 'status' => 'success']);
// update session tracking with new data
$session = App::get('session');
$session->set('tracker.user_id', $xuser->get('id'));
$session->set('tracker.username', $xuser->get('username'));
if ($session->get('tracker.sid') == '') {
$session->set('tracker.sid', $session->getId());
}
$session->set('tracker.psid', $session->get('tracker.sid'));
if ($session->get('tracker.rsid') == '') {
$session->set('tracker.rsid', $session->getId());
}
if ($session->get('tracker.user_id') != $xuser->get('id') || $session->get('tracker.ssid') == '') {
$session->set('tracker.ssid', $session->getId());
}
if (empty($user['type'])) {
$session->clear('session.authenticator');
} else {
$session->set('session.authenticator', $user['type']);
}
if (isset($options['silent']) && $options['silent']) {
$session->set('session.source', 'cookie');
} else {
$session->set('session.source', 'user');
}
// update tracking data with changes related to login
jimport('joomla.utilities.utility');
$hash = App::hash(App::get('client')->name . ':tracker');
$key = \App::hash('');
$crypt = new \Hubzero\Encryption\Encrypter(new \Hubzero\Encryption\Cipher\Simple(), new \Hubzero\Encryption\Key('simple', $key, $key));
$tracker = array();
$tracker['user_id'] = $session->get('tracker.user_id');
$tracker['username'] = $session->get('tracker.username');
$tracker['sid'] = $session->getId();
$tracker['rsid'] = $session->get('tracker.rsid', $tracker['sid']);
$tracker['ssid'] = $session->get('tracker.ssid', $tracker['sid']);
$cookie = $crypt->encrypt(serialize($tracker));
$lifetime = time() + 365 * 24 * 60 * 60;
// Determine whether cookie should be 'secure' or not
$secure = false;
$forceSsl = \Config::get('force_ssl', false);
if (\App::isAdmin() && $forceSsl >= 1) {
$secure = true;
} else {
if (\App::isSite() && $forceSsl == 2) {
$secure = true;
}
}
setcookie($hash, $cookie, $lifetime, '/', '', $secure, true);
/* Mark registration as incomplete so it gets checked on next page load */
$username = $xuser->get('username');
if (isset($user['auth_link']) && is_object($user['auth_link'])) {
$hzal = $user['auth_link'];
} else {
$hzal = null;
}
if ($xuser->get('tmp_user')) {
$email = $xuser->get('email');
if ($username[0] == '-') {
$username = trim($username, '-');
//.........这里部分代码省略.........
示例10: foreach
foreach ($a as $b) {
if (strstr($b, ':')) {
$b = explode(':', $b);
$bits[] = trim($b[0]) . '="' . trim($b[1]) . '"';
}
}
}
$attributes = implode(' ', $bits);
}
// Formats that can be previewed via Google viewer
$docs = array('pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pages', 'ai', 'psd', 'tiff', 'dxf', 'eps', 'ps', 'ttf', 'xps', 'svg');
$html5video = array("mp4", "m4v", "webm", "ogv");
$token = '';
if (!User::isGuest()) {
$session_id = App::get('session')->getId();
$key = App::hash(@$_SERVER['HTTP_USER_AGENT']);
$crypter = new \Hubzero\Encryption\Encrypter(new \Hubzero\Encryption\Cipher\Simple(), new \Hubzero\Encryption\Key('simple', $key, $key));
$token = base64_encode($crypter->encrypt($session_id));
}
$downloadUrl = Route::url('index.php?option=com_publications&id=' . $this->publication->id . '&task=serve&aid=' . $this->aid . '&render=download&token=' . $token);
$viewUrl = Route::url('index.php?option=com_publications&id=' . $this->publication->id . '&task=serve&aid=' . $this->aid . '&render=download&disposition=inline&token=' . $token);
?>
<div class="sample">
<p><?php
echo Lang::txt('COM_PUBLICATIONS_PUBLICATION') . ': <strong>' . $this->publication->title . '</strong>';
?>
<?php
if ($this->primary->role != 1) {
echo ' Supporting Doc: <strong>' . $this->primary->path . '</strong>';
}
?>
示例11: getEncrypter
/**
* Get the encrypter utility
*
* @return void
*/
protected static function getEncrypter()
{
$key = \App::hash(@$_SERVER['HTTP_USER_AGENT']);
$crypt = new \Hubzero\Encryption\Encrypter(new \Hubzero\Encryption\Cipher\Simple(), new \Hubzero\Encryption\Key('simple', $key, $key));
return $crypt;
}
示例12: getSessionIdFromCookie
/**
* Get session id from cookie
*
* [!] This will determine if the user has an active session via browser
*
* @return bool Result of test
*/
public function getSessionIdFromCookie()
{
// get session id key name
$sessionName = md5(\App::hash('site'));
// return session id stored in cookie
return !empty($_COOKIE[$sessionName]) ? $_COOKIE[$sessionName] : null;
}
示例13: invoke
/**
* Generate a Windows tool invoke URL to redirect to
*
* @param string $option Name of the component
* @return void
*/
public function invoke($option)
{
$no_html = Request::getInt('no_html', 0);
$response = new StdClass();
$response->success = false;
$response->message = Lang::txt('No invoke URL found.');
// Check for an imconing token.
if ($token = Request::getVar('token', '', 'get')) {
$dtoken = base64_decode($token);
$key = App::hash(@$_SERVER['HTTP_USER_AGENT']);
$crypter = new \Hubzero\Encryption\Encrypter(new \Hubzero\Encryption\Cipher\Simple(), new \Hubzero\Encryption\Key('simple', $key, $key));
$session_id = $crypter->decrypt($dtoken);
$session = \Hubzero\Session\Helper::getSession($session_id);
$user = User::getInstance($session->userid);
$user->set('guest', 0);
$user->set('id', $session->userid);
$user->set('username', $session->username);
$ip = $session->ip;
} else {
$user = User::getInstance();
$ip = Request::ip();
}
// Is the user validated?
if ($user->isGuest()) {
$response->message = Lang::txt('Login is required to perform this action.');
} else {
$appid = Request::getVar('appid');
// Generate the URL
$url = $this->generateInvokeUrl($option, $appid, $user, $ip);
if ($url) {
if (!$token) {
$session = App::get('session');
$session_id = $session->getId();
$key = App::hash(@$_SERVER['HTTP_USER_AGENT']);
$crypter = new \Hubzero\Encryption\Encrypter(new \Hubzero\Encryption\Cipher\Simple(), new \Hubzero\Encryption\Key('simple', $key, $key));
$token = base64_encode($crypter->encrypt($session_id));
}
$rurl = rtrim($this->params->get('invoke_url', 'http://wapps.hubzero.org'), '/') . '/v1?';
//standaloneUrl=' . $url;
$params = array();
$params[] = 'token=' . $token;
if ($appid) {
$params[] = 'appid=' . $appid;
}
$params[] = 'standaloneUrl=' . $url;
$rurl .= implode('&', $params);
$response->success = true;
$response->message = $rurl;
if (!$no_html) {
$this->view('invoke', 'display')->set('url', $rurl)->set('rurl', $_SERVER['HTTP_REFERER'])->display();
exit;
App::redirect($url);
}
}
}
if (!$no_html) {
App::abort(404, Lang::txt('No invoke URL found.'));
}
$response = json_encode($response);
if ($callback = Request::getVar('callback')) {
$response = $callback . '(' . $response . ')';
}
echo $response;
exit;
}
示例14: getEncrypter
/**
* Get the encrypter utility
*
* @return void
*/
protected static function getEncrypter()
{
$key = \App::hash('newletter');
$crypt = new \Hubzero\Encryption\Encrypter(new \Hubzero\Encryption\Cipher\Simple(), new \Hubzero\Encryption\Key('simple', $key, $key));
return $crypt;
}
示例15: getHash
/**
* Provides a secure hash based on a seed
*
* @param string $seed Seed string.
*
* @return string A secure hash
*
* @since 11.1
*/
public static function getHash($seed)
{
if (class_exists('\\App')) {
return \App::hash($seed);
}
return md5(JFactory::getConfig()->get('secret') . $seed);
}