本文整理汇总了PHP中sha1函数的典型用法代码示例。如果您正苦于以下问题:PHP sha1函数的具体用法?PHP sha1怎么用?PHP sha1使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sha1函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionModify
function actionModify()
{
$id = (int) $this->_context->get('id');
$rs = Account::find('user_id = ?', $id)->getOne();
if (!$rs->id()) {
return $this->msg($tip = '参数错误', url('manage::account'));
}
$form = Form_Common::createForm('', 'manage/profile');
if ($this->_context->isPOST() && $form->validate($_POST)) {
$post = $form->values();
$user_mail = $post['user_mail'];
$user_pass = $post['user_pass'];
$is_locked = $post['is_locked'] ? '1' : '0';
#dump($post);
if ($user_pass) {
$user_pass = sha1(md5('sike' . $post['user_pass'] . Q::ini('appini/secret_key')));
$rs->user_pass;
}
$rs->user_mail = $user_mail;
$rs->is_locked = $is_locked;
$rs->save();
return $this->msg($tip = '修改成功', url('manage::account/modify', array('id' => $id)));
}
$form->import($rs->toArray());
$form->element('user_pass')->value = '';
$form->element('is_locked')->checked = $rs->is_locked;
#dump($form->element('is_locked'));
$this->_view['form'] = $form;
$this->_view['rs'] = $rs;
$order = Order::find('user_id = ?', $id)->order('created DESC')->getAll();
$this->_view['order'] = $order;
$this->_view['_UDI'] = 'manage::account/index';
}
示例2: assignfeedback_editpdf_pluginfile
/**
* Serves assignment feedback and other files.
*
* @param mixed $course course or id of the course
* @param mixed $cm course module or id of the course module
* @param context $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
* @return bool false if file not found, does not return if found - just send the file
*/
function assignfeedback_editpdf_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload)
{
global $USER, $DB, $CFG;
if ($context->contextlevel == CONTEXT_MODULE) {
require_login($course, false, $cm);
$itemid = (int) array_shift($args);
if (!($assign = $DB->get_record('assign', array('id' => $cm->instance)))) {
return false;
}
$record = $DB->get_record('assign_grades', array('id' => $itemid), 'userid,assignment', MUST_EXIST);
$userid = $record->userid;
if ($assign->id != $record->assignment) {
return false;
}
// Check is users feedback or has grading permission.
if ($USER->id != $userid and !has_capability('mod/assign:grade', $context)) {
return false;
}
$relativepath = implode('/', $args);
$fullpath = "/{$context->id}/assignfeedback_editpdf/{$filearea}/{$itemid}/{$relativepath}";
$fs = get_file_storage();
if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
return false;
}
// Download MUST be forced - security!
send_stored_file($file, 0, 0, true);
// Check if we want to retrieve the stamps.
}
}
示例3: authorizeTask
/**
* Authorize
*
* @return void
*/
public function authorizeTask()
{
$oauth_token = \Request::getVar('oauth_token');
if (empty($oauth_token)) {
throw new Exception('Forbidden', 403);
}
$db = \App::get('db');
$db->setQuery("SELECT * FROM `#__oauthp_tokens` WHERE token=" . $db->Quote($oauth_token) . " AND user_id=0 LIMIT 1;");
$result = $db->loadObject();
if ($result === false) {
throw new Exception('Internal Server Error', 500);
}
if (empty($result)) {
throw new Exception('Forbidden', 403);
}
if (Request::method() == 'GET') {
$this->view->oauth_token = $oauth_token;
$this->view->display();
return;
}
if (Request::method() == 'POST') {
$token = Request::get('token', '' . 'post');
if ($token != sha1($this->verifier)) {
throw new Exception('Forbidden', 403);
}
echo "posted";
return;
}
throw new Exception('Method Not Allowed', 405);
}
示例4: ghost_command
public static function ghost_command($nick, $ircdata = array())
{
$unick = $ircdata[0];
$password = $ircdata[1];
// get the parameters.
if (trim($unick) == '' || trim($password) == '') {
services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_INVALID_SYNTAX_RE, array('help' => 'GHOST'));
return false;
}
// invalid syntax
if (!isset(core::$nicks[$unick])) {
services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_NOT_IN_USE, array('nick' => $unick));
return false;
// nickname isn't in use
}
if ($user = services::user_exists($unick, false, array('display', 'pass', 'salt'))) {
if ($user->pass == sha1($password . $user->salt) || core::$nicks[$nick]['ircop'] && services::user_exists($nick, true, array('display', 'identified')) !== false) {
ircd::kill(core::$config->nickserv->nick, $unick, 'GHOST command used by ' . core::get_full_hostname($nick));
core::alog(core::$config->nickserv->nick . ': GHOST command used on ' . $unick . ' by ' . core::get_full_hostname($nick));
} else {
services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_INVALID_PASSWORD);
// password isn't correct
}
} else {
services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_ISNT_REGISTERED, array('nick' => $unick));
return false;
// doesn't even exist..
}
}
示例5: addUser
public function addUser($add = array())
{
if (empty($add['staff_name']) and empty($add['username']) and empty($add['password'])) {
return TRUE;
}
$this->db->where('staff_email', strtolower($add['site_email']));
$this->db->delete('staffs');
$this->db->set('staff_email', strtolower($add['site_email']));
$this->db->set('staff_name', $add['staff_name']);
$this->db->set('staff_group_id', '11');
$this->db->set('staff_location_id', '0');
$this->db->set('language_id', '11');
$this->db->set('timezone', '0');
$this->db->set('staff_status', '1');
$this->db->set('date_added', mdate('%Y-%m-%d', time()));
$query = $this->db->insert('staffs');
if ($this->db->affected_rows() > 0 and $query === TRUE) {
$staff_id = $this->db->insert_id();
$this->db->where('username', $add['username']);
$this->db->delete('users');
$this->db->set('username', $add['username']);
$this->db->set('staff_id', $staff_id);
$this->db->set('salt', $salt = substr(md5(uniqid(rand(), TRUE)), 0, 9));
$this->db->set('password', sha1($salt . sha1($salt . sha1($add['password']))));
$query = $this->db->insert('users');
}
return $query;
}
示例6: actionUpdate
/**
* Updates an existing User model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$model->setScenario('update');
$oldFile = $model->getImageFile();
$oldImage = $model->pict;
if ($model->load(Yii::$app->request->post())) {
$model->attributes = $model->load(Yii::$app->request->post());
if (!empty($model->newpass)) {
$model->password = sha1($model->salt . $model->newpass);
}
$image = $model->uploadImage();
// revert back if image not valid
if ($image === FALSE) {
$model->pict = $oldImage;
}
if ($model->save()) {
// upload jika image nya valid
if ($image !== FALSE) {
if (is_file($oldFile)) {
unlink($oldFile);
}
$path = $model->getImageFile();
$image->saveAs($path);
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', ['model' => $model]);
}
} else {
return $this->render('update', ['model' => $model]);
}
}
示例7: sign
/**
* Create the signed assertion.
* @param string $openid - Openid of the entity being asserted.
* @param string $attribute - The attribute name being asserted.
* @param string $value - The attribute value being asserted.
*/
function sign($openid, $attribute, $value)
{
$samlObj = new SAML();
$responseXmlString = $samlObj->createSamlAssertion($openid, $this->notBefore, $this->notOnOrAfter, $this->rsadsa, $this->acsURI, $attribute, sha1($value), $this->assertionTemplate);
$signedAssertion = $samlObj->signAssertion($responseXmlString, $this->private_key, $this->public_key_certificate);
return $signedAssertion;
}
示例8: _addLocalization
/**
* Add localization data to xml object
*
* @param Mage_XmlConnect_Model_Simplexml_Element $xml
* @return Mage_XmlConnect_Block_Adminhtml_Connect_Config
*/
protected function _addLocalization(Mage_XmlConnect_Model_Simplexml_Element $xml)
{
/** @var $translateHelper Mage_XmlConnect_Helper_Translate */
$translateHelper = Mage::helper('xmlconnect/translate');
$xml->addCustomChild('localization', $this->getUrl('*/*/localization'), array('hash' => sha1(serialize($translateHelper->getLocalizationArray()))));
return $this;
}
示例9: hash
/**
* Create a security hash from the job, email and contact ids
*
* @param array The ids to be hashed
* @return int The hash
* @access public
* @static
*/
function hash($params)
{
$jobId = $params['job_id'];
$emailId = $params['email_id'];
$contactId = $params['contact_id'];
return sha1("{$jobId}:{$emailId}:{$contactId}:" . time());
}
示例10: join
/**
* 加密/校验流程:
* 1. 将token、timestamp、nonce三个参数进行字典序排序
* 2. 将三个参数字符串拼接成一个字符串进行sha1加密
* 3. 开发者获得加密后的字符串可与signature对比,标识该请求来源于易信
*
* 若确认此次GET请求来自易信服务器,请原样返回echostr参数内容,则接入生效,否则接入失败。
*/
public function join($params)
{
$signature = $params['signature'];
$timestamp = $params['timestamp'];
$nonce = $params['nonce'];
$echostr = $params['echostr'];
$mpa = TMS_APP::G('mp\\mpaccount');
$p = array($mpa->token, $timestamp, $nonce);
asort($p);
$s = implode('', $p);
$ss = sha1($s);
if ($ss === $signature) {
/**
* 断开连接
*/
TMS_APP::model()->update('xxt_mpaccount', array('yx_joined' => 'N'), "yx_appid='{$mpa->yx_appid}' and yx_appsecret='{$mpa->yx_appsecret}'");
/**
* 确认建立连接
*/
TMS_APP::model()->update('xxt_mpaccount', array('yx_joined' => 'Y'), "mpid='{$this->mpid}'");
return array(true, $echostr);
} else {
return array(false, 'failed');
}
}
示例11: validateDigest
public function validateDigest($digest, $nonce, $created, $secret)
{
// Generate created Token time difference
$now = new \DateTime('now', new \DateTimeZone('UTC'));
$then = new \Datetime($created, new \DateTimeZone('UTC'));
$diff = $now->diff($then, true);
// Check created time is not in the future
if (strtotime($created) > time()) {
throw new AuthenticationException("Back to the future...");
}
// Validate timestamp is recent within 5 minutes
$seconds = time() - strtotime($created);
if ($seconds > 300) {
throw new AuthenticationException('Expired timestamp. Seconds: ' . $seconds);
}
// Validate nonce is unique within 5 minutes
if (file_exists($this->cacheDir . '/' . $nonce) && file_get_contents($this->cacheDir . '/' . $nonce) + 300 > time()) {
throw new NonceExpiredException('Previously used nonce detected');
}
if (!is_dir($this->cacheDir)) {
mkdir($this->cacheDir, 0777, true);
}
file_put_contents($this->cacheDir . '/' . $nonce, time());
// Validate Secret
$expected = base64_encode(sha1(base64_decode($nonce) . $created . $secret, true));
// Return TRUE if our newly-calculated digest is the same as the one provided in the validateDigest() call
return $expected === $digest;
}
示例12: ajaxSignIn
public function ajaxSignIn()
{
extract($_POST['input']);
if (isset($remember)) {
\Models\Auth::remember($username, $password);
}
$user = Models\User::signIn($username, sha1($password));
if (!isset($user['id'])) {
$data['name'] = 'password';
$data['notice'] = 'Invalid login or password. Please try again.';
echo json_encode($data, JSON_UNESCAPED_UNICODE);
die;
}
$activated_at = \Models\User::getUserActivatedAt($username, sha1($password));
if (!isset($activated_at['activated_at']) || $activated_at['activated_at'] == null) {
$data['name'] = 'password';
$data['notice'] = 'Your account is not activated. Please, activate it at first.';
echo json_encode($data, JSON_UNESCAPED_UNICODE);
die;
} else {
\Models\Auth::userInSession($user);
$data['notice'] = true;
$data['id'] = $user['id'];
echo json_encode($data, JSON_UNESCAPED_UNICODE);
die;
}
}
示例13: testSetPath
public function testSetPath()
{
$exporter = $this->getMockForAbstractClass(AbstractExporter::class);
$path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . sha1(time()) . DIRECTORY_SEPARATOR;
$exporter->setPath($path);
$this->assertEquals($path, $exporter->getPath());
}
示例14: connect
public function connect()
{
if ($this->_connection) {
return;
}
// Extract the connection parameters, adding required variabels
extract($this->_config['connection'] + array('hostname' => '', 'port' => '', 'password' => '', 'timeout' => 2.5, 'lifetime' => 1800, 'persistent' => FALSE));
// Prevent this information from showing up in traces
unset($this->_config['connection']['password']);
$this->_connection = new Redis();
try {
if ($persistent) {
// Create a persistent connection
$this->_connection->pconnect($hostname, $port, $timeout);
} else {
// Create a connection and force it to be a new link
$this->_connection->connect($hostname, $port, $timeout);
}
} catch (Exception $e) {
// No connection exists
$this->_connection = NULL;
throw new Redis_Exception(':error', array(':error' => $e->getMessage()), $e->getCode());
}
// \xFF is a better delimiter, but the PHP driver uses underscore
$this->_connection_id = sha1($hostname . '_' . $password);
if (!empty($this->_config['connection']['variables'])) {
// Set session variables
$variables = array();
foreach ($this->_config['connection']['variables'] as $var => $val) {
$variables[] = 'SESSION ' . $var . ' = ' . $this->quote($val);
}
//mysql_query('SET '.implode(', ', $variables), $this->_connection);
}
}
示例15: get_capsidea_data
function get_capsidea_data($capsidea_client_secret)
{
$ret = array();
$parsed_url = parse_url($_SERVER['HTTP_REFERER']);
$var = explode('&', $parsed_url['query']);
foreach ($var as $val) {
$x = explode('=', $val);
$arr[$x[0]] = $x[1];
}
unset($val, $x, $var, $qry, $parsed_url, $ref);
if (isset($arr["token"])) {
$token = $arr["token"];
} else {
die("cant find capsidea.com token, please contact application support");
}
if (36 != strlen($token)) {
die("capsidea.com token incorrect, please contact application support");
}
$ret["c"] = $str = preg_replace('/[^A-Za-z0-9\\-]/', '', $token);
$ret["t"] = sha1($capsidea_client_secret . $token);
if (isset($arr["schemakey"])) {
$ret["k"] = (int) $arr["schemakey"];
}
return $ret;
}