本文整理汇总了PHP中hmac函数的典型用法代码示例。如果您正苦于以下问题:PHP hmac函数的具体用法?PHP hmac怎么用?PHP hmac使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hmac函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: confirmUser
function confirmUser($username, $password)
{
global $conn;
/* Add slashes if necessary (for query) */
if (!get_magic_quotes_gpc()) {
$username = addslashes($username);
}
/* Verify that user is in database */
$q = "select password from " . DB_PREFIX . "users where username = '{$username}' limit 1";
$result = mysql_query($q, $conn);
if (!$result || mysql_numrows($result) < 1) {
return 1;
// Indicates username failure
}
/* Retrieve password from result, strip slashes */
$dbarray = mysql_fetch_array($result);
// combine password in database with key
$dbarray['password'] = hmac($_SESSION['key'], stripslashes($dbarray['password']));
$password = stripslashes($password);
/* Validate that password is correct */
if ($password == $dbarray['password']) {
return 0;
// Success! Username and password confirmed
} else {
return 2;
// Indicates password failure
}
}
示例2: _sign
private function _sign($data)
{
if (is_null($this->_macKey)) {
throw new Exception("EMPTY_MACKEY");
}
return hmac($this->_macKey, $data);
}
示例3: _verifySign
private function _verifySign($domain, $text, $sign)
{
include_once KFL_DIR . '/Libs/Cache.class.php';
$filename = $domain . ".txt";
$cache = new Cache(86400 * 300, 0);
$cache->setCacheStore("file");
// or memcache
$cache->setCacheDir(APP_TEMP_DIR);
$cache->setCacheFile($filename);
if ($cache->isCached()) {
$client = unserialize($cache->fetch());
} else {
require_once 'ClientModel.class.php';
$ClientModel = new ClientModel();
$client = $ClientModel->getClientByName($domain);
if ($client) {
$cache->save(serialize($client));
} else {
return false;
}
}
$this->_private_key = $client['private_key'];
if (hmac($this->_private_key, $text, 'sha1') == $sign) {
return true;
} else {
return false;
}
}
示例4: gda_add_hash
function gda_add_hash($key, $text)
{
if ($key == "") {
return "NOHASH\n" . $text;
} else {
return hmac($key, $text) . "\n" . $text;
}
}
示例5: InsertFP
function InsertFP ($loginid, $x_tran_key, $amount, $sequence, $currency = "")
{
$tstamp = time ();
$fingerprint = hmac ($x_tran_key, $loginid . "^" . $sequence . "^" . $tstamp . "^" . $amount . "^" . $currency);
echo ('<input type="hidden" name="x_fp_sequence" value="' . $sequence . '">' );
echo ('<input type="hidden" name="x_fp_timestamp" value="' . $tstamp . '">' );
echo ('<input type="hidden" name="x_fp_hash" value="' . $fingerprint . '">' );
return (0);
}
示例6: decrypt
function decrypt($key, $data)
{
$decodedData = base64_decode($data);
// TODO: Check that data is at least bigger than HMAC + IV length
error_log("key in Decrypt is: " . $key);
$hmac = substr($decodedData, 0, 32);
error_log("hmac in Decrypt is: " . $hmac);
$iv = substr($decodedData, 32, 16);
error_log("iv in Decrypt is: " . $iv);
$data = substr($decodedData, 48);
error_log("data in Decrypt is: " . $data);
if ($hmac != hmac($key, $iv . $data)) {
// TODO: Handle HMAC validation failure
return 0;
}
//echo "no error";
return openssl_decrypt($data, 'aes-256-cbc', hashKey($key), true, $iv);
}
示例7: checkLogin
function checkLogin()
{
/* Check if user has been remembered */
if (isset($_COOKIE['c_name']) && isset($_COOKIE['c_pass'])) {
$_SESSION['username'] = $_COOKIE['c_name'];
$_SESSION['password'] = hmac($_SESSION['key'], $_COOKIE['c_pass']);
}
/* Username and password have been set */
if (isset($_SESSION['username']) && isset($_SESSION['password'])) {
/* Confirm that username and password are valid */
if (confirmUser($_SESSION['username'], $_SESSION['password']) != 0) {
/* Variables are incorrect, user not logged in */
unset($_SESSION['username']);
unset($_SESSION['password']);
// reset cookies
if (isset($_COOKIE['c_name'])) {
setcookie("c_name", "", time() - 60 * 60 * 24 * 100, "/");
}
if (isset($_COOKIE['c_pass'])) {
setcookie("c_pass", "", time() - 60 * 60 * 24 * 100, "/");
}
return false;
}
// log user data
if (!isset($_SESSION['logged'])) {
$_SESSION['logged'] = true;
global $conn;
/* Add slashes if necessary (for query) */
$username = $_SESSION['username'];
$ip = $_SERVER['REMOTE_ADDR'];
if (!get_magic_quotes_gpc()) {
$username = addslashes($username);
$ip = addslashes($ip);
}
$q = "UPDATE " . DB_PREFIX . "users SET ip = '{$ip}', lastdate = " . time() . " WHERE username = '{$username}'";
mysql_query($q, $conn);
}
return true;
} else {
return false;
}
}
示例8: die
die('Этот заказ уже оплачен');
} else {
$url = $okay->config->root_url . '/order/' . $order->url;
header('location:' . $url);
exit;
}
}
////////////////////////////////////
// Проверка контрольной подписи
////////////////////////////////////
if ($_REQUEST['check'] == "1") {
$param = $_REQUEST['ext_transact'] . $_REQUEST['num_shop'] . $_REQUEST['keyt_shop'] . $_REQUEST['identified'] . $_REQUEST['sum'] . $_REQUEST['comment'];
$sign = hmac($settings['skeys'], $param);
} else {
$param = $_REQUEST['transact'] . $_REQUEST['status'] . $_REQUEST['result'] . $_REQUEST['ext_transact'] . $_REQUEST['num_shop'] . $_REQUEST['keyt_shop'] . '1' . $_REQUEST['sum'] . $_REQUEST['comment'];
$sign = hmac($settings['skeys'], $param);
}
if ($sign != $_REQUEST['sign']) {
if ($_REQUEST['check'] == "1") {
die("Контрольная подпись не верна");
} else {
$url = $okay->config->root_url . '/order/' . $order->url;
header('location:' . $url);
exit;
}
}
////////////////////////////////////
// Проверка суммы платежа
////////////////////////////////////
// Сумма заказа у нас в магазине
$order_amount = $okay->money->convert($order->total_price, $method->currency_id, false);
示例9: do_userform
//.........这里部分代码省略.........
$opts['id'] = 'nobody';
$ticket = base64_encode(getTicket($_SERVER['REMOTE_ADDR'], $opts['email'], 10));
$enc = base64_encode($opts['email']);
$body = qualifiedUrl($formatter->link_url('UserPreferences', "?action=userform&login={$enc}&verify_email={$ticket}"));
$body = _("Please confirm your e-mail address") . "\n" . $body . "\n";
$ret = wiki_sendmail($body, $opts);
$options['msg'] .= '<br/>' . _("E-mail verification mail sent");
}
}
}
} else {
$options['msg'] .= '<br/>' . _("Your email address is not valid");
}
} else {
if ($user->id == "Anonymous" and !empty($options['login_id']) and isset($options['password']) and !isset($options['passwordagain'])) {
if (method_exists($user, 'login')) {
$user->login($formatter, $options);
$params = array();
$params['value'] = $options['page'];
do_goto($formatter, $params);
return;
}
# login
$userdb = $DBInfo->udb;
if ($userdb->_exists($id)) {
$user = $userdb->getUser($id);
$login_ok = 0;
if (!empty($DBInfo->use_safelogin)) {
if (isset($options['challenge']) and $options['_chall'] == $options['challenge']) {
#print '<pre>';
#print $options['password'].'<br />';
#print hmac($options['challenge'],$user->info['password']);
#print '</pre>';
if (hmac($options['challenge'], $user->info['password']) == $options['password']) {
$login_ok = 1;
}
} else {
# with no javascript browsers
$md5pw = md5($options['password']);
if ($md5pw == $user->info['password']) {
$login_ok = 1;
}
}
}
if ($login_ok or $user->checkPasswd($options['password']) === true) {
$options['msg'] = sprintf(_("Successfully login as '%s'"), $id);
$options['id'] = $user->id;
if ($user->id == 'Anonymous') {
// special case. login success but ID is not acceptable
$options['msg'] = _("Invalid user ID. Please register again");
} else {
$formatter->header($user->setCookie());
if (!isset($user->info['login_success'])) {
$user->info['login_success'] = 0;
}
if (!isset($user->info['login_fail'])) {
$user->info['login_fail'] = 0;
}
$user->info['login_success']++;
$user->info['last_login'] = gmdate("Y/m/d H:i:s", time());
$user->info['login_fail'] = 0;
// reset login
$user->info['remote'] = $_SERVER['REMOTE_ADDR'];
$userdb->saveUser($user);
$use_refresh = 1;
}
示例10: sdb_request
function sdb_request($action, $params = array())
{
global $adminer, $connection;
list($host, $params['AWSAccessKeyId'], $secret) = $adminer->credentials();
$params['Action'] = $action;
$params['Timestamp'] = gmdate('Y-m-d\\TH:i:s+00:00');
$params['Version'] = '2009-04-15';
$params['SignatureVersion'] = 2;
$params['SignatureMethod'] = 'HmacSHA1';
ksort($params);
$query = '';
foreach ($params as $key => $val) {
$query .= '&' . rawurlencode($key) . '=' . rawurlencode($val);
}
$query = str_replace('%7E', '~', substr($query, 1));
$query .= "&Signature=" . urlencode(base64_encode(hmac('sha1', "POST\n" . preg_replace('~^https?://~', '', $host) . "\n/\n{$query}", $secret, true)));
@ini_set('track_errors', 1);
// @ - may be disabled
$file = @file_get_contents(preg_match('~^https?://~', $host) ? $host : "http://{$host}", false, stream_context_create(array('http' => array('method' => 'POST', 'content' => $query, 'ignore_errors' => 1))));
if (!$file) {
$connection->error = $php_errormsg;
return false;
}
libxml_use_internal_errors(true);
$xml = simplexml_load_string($file);
if (!$xml) {
$error = libxml_get_last_error();
$connection->error = $error->message;
return false;
}
if ($xml->Errors) {
$error = $xml->Errors->Error;
$connection->error = "{$error->Message} ({$error->Code})";
return false;
}
$connection->error = '';
$tag = $action . "Result";
return $xml->{$tag} ? $xml->{$tag} : true;
}
示例11: hmac
<input type=hidden name=x_show_form value="PAYMENT_FORM">
<input type=hidden name=x_relay_response value="TRUE">
<input type=hidden name=x_login value="<?php
print $authorize_login;
?>
">
<input type=hidden name=x_fp_sequence value="<?php
print $r->id;
?>
">
<input type=hidden name=x_fp_timestamp value="<?php
print $x_time;
?>
">
<input type=hidden name=x_fp_hash value="<?php
print hmac($authorize_secret, $authorize_login . "^" . $r->id . "^" . $x_time . "^" . sprintf("%01.2f", $money_authorize) . "^");
?>
">
<input type=hidden name=x_receipt_link_url value="<?php
print GetSetting("payment_url");
?>
">
<input type=hidden name=x_relay_url value="<?php
print $full_www_path . "online_authorize.php";
?>
">
<input type=hidden name=x_description value="<?php
print $company_name;
?>
: bill <?php
print $sid;
示例12: build_signature
public function build_signature($request, $consumer, $token)
{
$base_string = $request->get_signature_base_string();
$request->base_string = $base_string;
$key_parts = array(!empty($consumer->secret) ? $consumer->secret : '', $token ? $token->secret : "");
$key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
$key = implode('&', $key_parts);
if (!function_exists('hash_hmac')) {
return base64_encode(hmac($key, $base_string));
} else {
return base64_encode(hash_hmac('sha1', $base_string, $key, true));
}
}
示例13: checkid
private function checkid($wait)
{
if (empty($_REQUEST['openid_return_to'])) {
return $this->error400('return_to');
}
$return_to = $_REQUEST['openid_return_to'];
if (empty($_REQUEST['openid_identity'])) {
return $this->error_get($return_to, 'identity');
}
$identity = $_REQUEST['openid_identity'];
if ($identity != litepublisher::$site->url . $this->url) {
return $this->error_get($return_to, 'identity');
}
$trust_root = !empty($_REQUEST['openid_trust_root']) ? $_REQUEST['openid_trust_root'] : $return_to;
if ($trust_root != $return_to) {
if (!$this->urldescends($return_to, $trust_root)) {
return $this->error500('Invalidtrust');
}
}
$assoc_handle = !empty($_REQUEST['openid_assoc_handle']) ? $_REQUEST['openid_assoc_handle'] : null;
$sreg_required = !empty($_REQUEST['openid_sreg_required']) ? $_REQUEST['openid_sreg_required'] : '';
$sreg_optional = !empty($_REQUEST['openid_sreg_optional']) ? $_REQUEST['openid_sreg_optional'] : '';
//join fields
$sreg_required .= ',' . $sreg_optional;
$auth = tauthdigest::i();
if (litepublisher::$options->cookieenabled) {
if (!litepublisher::$options->user) {
return litepublisher::$urlmap->redir('/admin/login/');
}
} elseif (!$auth->Auth()) {
return $auth->headers();
}
if (litepublisher::$options->group != 'admin') {
return 404;
}
$q = strpos($return_to, '?') ? '&' : '?';
$cancel_url = $return_to . $q . 'openid.mode=cancel';
if ($wait && (!in_array($trust_root, $this->trusted) || $this->confirm)) {
//вывести форму и проверит результат формы
if (empty($_POST['submit'])) {
if (!empty($_REQUEST['openid_assoc_handle']) && isset($this->keys[$_REQUEST['openid_assoc_handle']])) {
$this->keys[$_REQUEST['openid_assoc_handle']]['request'] = $_REQUEST;
$this->save();
}
$html = tadminhtml::i();
$html->section = 'openidserver';
$lang = tlocal::i('openidserver');
$args = targs::i();
$args->trust_root = $trust_root;
$args->assoc_handle = $assoc_handle;
$form = $html->trustform($args);
return tsimplecontent::html($form);
} else {
switch ($_POST['accept']) {
case 'yes':
break;
case 'yesall':
$this->trusted[] = $trust_root;
$this->save();
break;
default:
return $this->redir($cancel_url);
}
}
}
$keys = array('mode' => 'id_res', 'identity' => litepublisher::$site->url . $this->url, 'return_to' => $return_to);
if (!($shared_secret = $this->GetSecret($assoc_handle))) {
if ($assoc_handle != null) {
$keys['invalidate_handle'] = $assoc_handle;
if (isset($this->keys[$assoc_handle])) {
unset($this->keys[$assoc_handle]);
}
}
$this->NewKeys($assoc_handle, $shared_secret, $lifetime);
}
$keys['assoc_handle'] = $assoc_handle;
foreach (explode(',', $sreg_required) as $key) {
if (!isset($_REQUEST[$key])) {
continue;
}
$skey = 'sreg.' . $key;
if ($value = $this->GetReg($key)) {
$keys[$skey] = $value;
}
}
$tokens = '';
foreach ($keys as $key => $value) {
$tokens .= "{$key}:{$value}\n";
}
$keys['signed'] = implode(',', array_keys($keys));
$keys['sig'] = base64_encode(hmac($shared_secret, $tokens));
return $this->RedirKeys($return_to, $keys);
}
示例14: checkPasswd
function checkPasswd($passwd, $chall = 0)
{
if (strlen($passwd) < 3) {
return false;
}
if ($chall) {
if (hmac($chall, $this->info['password']) == $passwd) {
return true;
}
} else {
if (crypt($passwd, $this->info['password']) == $this->info['password']) {
return true;
}
}
return false;
}
示例15: _createSign
private function _createSign($text)
{
return hmac($this->_private_key, $text, 'sha1');
}