本文整理汇总了PHP中Security::generateAuthKey方法的典型用法代码示例。如果您正苦于以下问题:PHP Security::generateAuthKey方法的具体用法?PHP Security::generateAuthKey怎么用?PHP Security::generateAuthKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Security
的用法示例。
在下文中一共展示了Security::generateAuthKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
/**
* undocumented function
*
* @return void
* @access public
*/
static function generate($key = array(), $autoRefresh = true)
{
if (Common::isUuid($key)) {
$key = array('user_id' => $key);
} elseif (!isset($key['user_id'])) {
$key['user_id'] = User::get('id');
}
// to support emails, too
// Assert::true(Common::isUuid($key['user_id']));
$_this = Common::getModel('AuthKey');
if (!Common::isUuid($key['auth_key_type_id']) && !empty($key['auth_key_type_id'])) {
$key['auth_key_type_id'] = $_this->AuthKeyType->lookup($key['auth_key_type_id']);
}
Assert::true(Common::isUuid($key['auth_key_type_id']));
$recursive = -1;
$sameTypeKey = $_this->find('first', array('conditions' => array('user_id' => $key['user_id'], 'auth_key_type_id' => $key['auth_key_type_id']), 'recursive' => -1));
if ($sameTypeKey) {
if (!$autoRefresh) {
return false;
}
$key['id'] = $sameTypeKey['AuthKey']['id'];
}
do {
$key['key'] = Security::generateAuthKey();
} while (!$_this->isUnique(array('key' => $key['key'])));
Assert::notEmpty($key['key']);
$_this->create();
Assert::notEmpty($_this->save($key));
return $key['key'];
}
示例2: checkout_recur_paypal
function checkout_recur_paypal($type = -1)
{
$this->loadModel("SubscriptionType");
$this->Session->write("TOKEN", null);
if ($type != -1) {
$type = $this->SubscriptionType->find("first", array("conditions" => array("SubscriptionType.id" => $type), "recursive" => -1));
$paymentInfo["Payment"]["paymentType"] = "Sale";
$paymentInfo["Payment"]["currencyCode"] = "USD";
$paymentInfo["Payment"]["amount"] = $type["SubscriptionType"]["price"];
$paymentInfo["Payment"]["description"] = $type["SubscriptionType"]["name"];
$key = Security::generateAuthKey();
$this->Session->write("Payment.transaction", $key);
$this->Session->write("Payment.type", $type);
$this->Session->write("Payment.amount", $type["SubscriptionType"]["price"]);
$paymentInfo["Payment"]["returnURL"] = "https://" . $_SERVER['SERVER_NAME'] . $this->base . "/subscription_transactions/success_recur_paypal/" . $key;
$paymentInfo["Payment"]["cancelURL"] = "https://" . $_SERVER['SERVER_NAME'] . $this->base . "/subscription_transactions/cancel_paypal/" . $key;
$paymentInfo["Payment"]["startDate"] = urlencode(date("Y-M-d") . "T" . date("h:m:s") . "Z");
$this->PaypalService->recurringPayment($paymentInfo);
if ($this->Session->check("TOKEN")) {
$this->PaypalService->redirectToPaypal($this->Session->read("TOKEN"));
} else {
$this->redirect("/subscribe");
}
} else {
$this->redirect("/subscribe");
}
}
示例3: add
public function add()
{
$this->loadModel('Department');
$this->loadModel('Meeting');
$this->set('dept', $this->Department->find('all', array('fields' => array('id', 'description'))));
if ($this->request->is('post')) {
$this->Meeting->create();
// Initialize filename-variable
$filename = null;
$today = getdate();
if (!empty($this->request->data['Meeting']['upload']['tmp_name']) && is_uploaded_file($this->request->data['Meeting']['upload']['tmp_name'])) {
// Strip path information
$filename = substr(Security::generateAuthKey(), 0, 5) . '_' . basename($this->request->data['Meeting']['upload']['name']);
move_uploaded_file($this->data['Meeting']['upload']['tmp_name'], WWW_ROOT . 'files' . DS . $filename);
}
//Set the file-name only to save in the database
$this->request->data['Meeting']['upload'] = $filename;
$this->request->data['Meeting']['upload_dir'] = WWW_ROOT . 'files' . DS . $filename;
if ($this->Meeting->save($this->request->data)) {
$this->Session->setFlash('Your post has been saved.');
$this->redirect('/meetings');
} else {
$this->Session->setFlash('Unable to add your post.');
}
}
}
示例4: generateVerification
/**
* Generates verification data for a Model.
*
* The verification key and code are two strings that can be used to verify a user is valid.
* The verification timestamp can be used to check if the verification data has expired.
*
* @param Model $Model Model using this behavior
* @param int $id The ID of the Model to generate verification data for
* @return mixed On success Model::$data if its not empty or true, false on failure
*/
public function generateVerification(Model $Model, $id = null)
{
if ($id) {
$Model->id = $id;
}
// No ID, so cannot save the verification data
if (!$Model->getID()) {
return false;
}
// Generate verification data
$data = array($Model->alias => array($Model->primaryKey => $id, $this->settings['fields']['key'] => Security::generateAuthKey(), $this->settings['fields']['code'] => uniqid(), $this->settings['fields']['timestamp'] => date("Y-m-d H:i:s"), 'modified' => false));
return $Model->save($data, false, array($Model->primaryKey, $this->settings['fields']['key'], $this->settings['fields']['code'], $this->settings['fields']['timestamp']));
}
示例5: add
/**
* add method
*
* @return void
*/
public function add()
{
if ($this->request->is('post')) {
$this->request->data['User']['passport'] = Security::generateAuthKey();
$this->User->create();
if ($this->User->save($this->request->data)) {
$this->Core->get_alert('ユーザーを追加しました。', 'success');
return $this->redirect(array('action' => 'index'));
} else {
$this->Core->get_alert('ユーザーを追加できませんでした。', 'danger');
}
}
$roles = $this->User->Role->find('list');
$this->set(compact('roles'));
}
示例6: step3
private function step3()
{
$missingDatabase = false;
if (!($databaseConfig = $this->Session->read('database'))) {
$missingDatabase = true;
}
if ($missingDatabase) {
$this->Session->setFlash(__('MushRaider can\'t find your database settings, please complete this form to proceed to next step'), 'flash_error');
$this->redirect('/install/step/2');
}
if (!empty($this->request->data['Config'])) {
$siteInfos = array('siteTitle' => trim($this->request->data['Config']['sitetitle']), 'siteLanguage' => trim($this->request->data['Config']['sitelang']), 'adminemail' => trim($this->request->data['Config']['adminemail']), 'adminlogin' => trim($this->request->data['Config']['adminlogin']), 'adminpassword' => md5($this->request->data['Config']['adminpassword']));
if (!empty($siteInfos['siteTitle']) && !empty($siteInfos['adminlogin']) && !empty($siteInfos['adminpassword'])) {
$settingsConfig = array();
$settingsConfig['language'] = $siteInfos['siteLanguage'];
$settingsConfig['salt'] = Security::generateAuthKey();
$settingsConfig['cipherSeed'] = mt_rand() . mt_rand();
$error = false;
if (!($mysqlLink = mysqli_connect($databaseConfig['host'], $databaseConfig['login'], $databaseConfig['password'], $databaseConfig['database'], $databaseConfig['port']))) {
$error = true;
}
// Create tables
$sqlReport = $this->Patcher->run_sql_file($mysqlLink, '../Config/Schema/sql/mushraider.sql', $databaseConfig['prefix']);
if ($sqlReport['success'] != $sqlReport['total']) {
$error = true;
}
// Add datas
$sqlReport = $this->Patcher->run_sql_file($mysqlLink, '../Config/Schema/sql/mushraider_data.sql', $databaseConfig['prefix']);
if ($sqlReport['success'] != $sqlReport['total']) {
$error = true;
}
$mysqlLink = null;
// No error, we continue by creating the admin user
if (!$error) {
Configure::write('Database', $this->Tools->quoteArray($databaseConfig));
Configure::dump('config.ini', 'configini', array('Database'));
$siteSettings = array('settingsConfig' => $settingsConfig, 'siteInfos' => $siteInfos);
$this->Session->write('siteSettings', $siteSettings);
$this->redirect('/install/step/4');
}
}
// Error
$this->Session->setFlash(__('MushRaider can\'t verify the settings, please be sure to fill all the fields to continue.'), 'flash_error');
}
}
示例7: createCroogoFile
public function createCroogoFile()
{
$croogoConfigFile = APP . 'Config' . DS . 'croogo.php';
copy($croogoConfigFile . '.install', $croogoConfigFile);
$File =& new File($croogoConfigFile);
$salt = Security::generateAuthKey();
$seed = mt_rand() . mt_rand();
$contents = $File->read();
$contents = preg_replace('/(?<=Configure::write\\(\'Security.salt\', \')([^\' ]+)(?=\'\\))/', $salt, $contents);
$contents = preg_replace('/(?<=Configure::write\\(\'Security.cipherSeed\', \')(\\d+)(?=\'\\))/', $seed, $contents);
if (!$File->write($contents)) {
CakeLog::critical('Unable to write your Config' . DS . 'croogo.php file. Please check the permissions.');
return false;
}
Configure::write('Security.salt', $salt);
Configure::write('Security.cipherSeed', $seed);
return true;
}
示例8: __setNewSaltSeed
private function __setNewSaltSeed()
{
// set new salt and seed value
$File =& new File(APP . 'Config' . DS . 'core.php');
$salt = Security::generateAuthKey();
$seed = mt_rand() . mt_rand();
$contents = $File->read();
$contents = preg_replace('/(?<=Configure::write\\(\'Security.salt\', \')([^\' ]+)(?=\'\\))/', $salt, $contents);
$contents = preg_replace('/(?<=Configure::write\\(\'Security.cipherSeed\', \')(\\d+)(?=\'\\))/', $seed, $contents);
if (!$File->write($contents)) {
$this->Flash->info(__('Unable to secure your application, your Config %s core.php file is not writable. Please check the permissions.', DS));
$this->log('Unable to secure your application, your Config %s core.php file is not writable. Please check the permissions.', DS);
return false;
}
Configure::write('Security.salt', $salt);
Configure::write('Security.cipherSeed', $seed);
return true;
}
示例9: serial
/**
* undocumented function
*
* @param string $id
* @param string $forceCreate
* @return void
* @access public
*/
function serial($Model, $id, $forceCreate = false)
{
$field = $this->__settings[$Model->alias]['field'];
$length = $this->__settings[$Model->alias]['length'];
App::import('Core', 'Security');
if (!$forceCreate) {
$key = $Model->lookup(compact('id'), $field, false);
if (!empty($key)) {
return $key;
}
}
do {
$key = Security::generateAuthKey();
$key = substr($key, 0, $length);
} while (!$Model->isUnique(array($field => $key)));
$Model->set(array('id' => $id, $field => $key));
$Model->save();
return $key;
}
示例10: glemt_passord
/**
Brukes til å sende en epost med lenke til
side for å få nytt passord
Setter tmp_key i databasen, som sendes med i lenken
@param @base_url er urlen til action "nytt passord". Denne må finnes fra controlleren
@param $username er brukernavnet
**/
function glemt_passord($username)
{
if (!is_string($username)) {
return $this->FEIL_BRUKERNAVN;
}
$userData = $this->find('first', array('conditions' => array('Selger.navn' => $username)));
if (!isset($userData['Selger'])) {
return $this->FEIL_BRUKERNAVN;
}
if (!isset($userData['Selger']['epost'])) {
return $this->INGEN_EPOST;
}
$epostAdr = $userData['Selger']['epost'];
$tmp_key = Security::generateAuthKey();
$userData['Selger']['tmp_key'] = $tmp_key;
$userData['Selger']['tmp_key_created'] = date('c');
$this->save($userData, false, array('tmp_key', 'tmp_key_created'));
$email = new CakeEmail('default');
$email->viewVars(array('tmp_key' => $userData['Selger']['tmp_key'], 'user_id' => $userData['Selger']['nummer'], 'epost' => $userData['Selger']['epost'], 'navn' => $userData['Selger']['navn']));
$email->template('nytt_passord', 'vanlig')->emailFormat('html')->to($userData['Selger']['epost'])->from("dag@zapatista.no")->subject("Passord tilbakestilling")->send();
return $this->OK;
}
示例11: finalize
/**
* Finalize installation
*
* Prepares Config/settings.yml and update password for admin user
* @param $user array user to create
* @return $mixed if false, indicates processing failure
*/
public function finalize($user)
{
if (Configure::read('Install.installed') && Configure::read('Install.secured')) {
return false;
}
copy(APP . 'Config' . DS . 'settings.yml.install', APP . 'Config' . DS . 'settings.yml');
// set new salt and seed value
if (!Configure::read('Install.secured')) {
$File =& new File(APP . 'Config' . DS . 'croogo.php');
$salt = Security::generateAuthKey();
$seed = mt_rand() . mt_rand();
$contents = $File->read();
$contents = preg_replace('/(?<=Configure::write\\(\'Security.salt\', \')([^\' ]+)(?=\'\\))/', $salt, $contents);
$contents = preg_replace('/(?<=Configure::write\\(\'Security.cipherSeed\', \')(\\d+)(?=\'\\))/', $seed, $contents);
if (!$File->write($contents)) {
$this->log('Unable to write your Config' . DS . 'croogo.php file. Please check the permissions.');
return false;
}
Configure::write('Security.salt', $salt);
Configure::write('Security.cipherSeed', $seed);
}
// create administrative user
$User = ClassRegistry::init('User');
$User->Role->Behaviors->attach('Aliasable');
unset($User->validate['email']);
$user['User']['name'] = $user['User']['username'];
$user['User']['email'] = '';
$user['User']['timezone'] = 0;
$user['User']['role_id'] = $User->Role->byAlias('admin');
$user['User']['status'] = true;
$user['User']['activation_key'] = md5(uniqid());
$data = $User->create($user['User']);
$saved = $User->save($data);
if (!$saved) {
$this->log('Unable to create administrative user. Validation errors:');
$this->log($User->validationErrors);
}
return $saved;
}
示例12: __setNewSaltSeed
private function __setNewSaltSeed()
{
// set new salt and seed value
if (Configure::read('Security.salt') == 'zshlC2wMeCWMnRH8BmqmLQUFeBIT4uwBGSMS4k1w' || Configure::read('Security.cipherSeed') == '2973937642728344649949541921993430529846') {
$File =& new File(APP . 'Config' . DS . 'core.php');
$salt = Security::generateAuthKey();
$seed = mt_rand() . mt_rand();
$contents = $File->read();
$contents = preg_replace('/(?<=Configure::write\\(\'Security.salt\', \')([^\' ]+)(?=\'\\))/', $salt, $contents);
$contents = preg_replace('/(?<=Configure::write\\(\'Security.cipherSeed\', \')(\\d+)(?=\'\\))/', $seed, $contents);
if (!$File->write($contents)) {
$this->Session->setFlash(__('Unable to secure your application, your Config %s core.php file is not writable. Please check the permissions.', DS), 'flash_message_info');
$this->log('Unable to secure your application, your Config %s core.php file is not writable. Please check the permissions.', DS);
return false;
}
Configure::write('Security.salt', $salt);
Configure::write('Security.cipherSeed', $seed);
}
return true;
}
示例13: beforeSave
/**
* Use hashing user password.
*
* @inheritdoc
*/
public function beforeSave($options = array())
{
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
$this->data[$this->alias]['token'] = Security::generateAuthKey();
return true;
}
示例14: forgot
public function forgot()
{
if ($this->request->data) {
$user = $this->User->findByEmailAndIsActive($this->request->data['User']['email'], 1);
if (!$user) {
$this->Session->setFlash('User nicht gefunden.', 'flash_fail');
$this->redirect(array('controller' => 'users', 'action' => 'forgot'));
}
$newAuthKey = Security::generateAuthKey();
$this->User->id = $user['User']['id'];
if ($this->User->saveField('activationkey', $newAuthKey)) {
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('default');
$email->to($user['User']['email'])->subject('open reNose | Passwort ändern')->template('forgot')->emailFormat('html')->viewVars(array('data' => $user, 'newAuthKey' => $newAuthKey));
try {
$email->send();
} catch (Exception $e) {
$this->Session->setFlash('Fehler beim Verschicken der Aktivierungs Mail.', 'flash_fail');
}
$this->Session->setFlash('E-Mail zur Passwortänderung wurde erfolgreich verschickt. Bitte prüfen Sie ihr E-Mail Postfach.', 'flash_success');
$this->redirect('/');
}
}
$this->set('title_for_layout', 'Passwort vergessen');
}
示例15: testValidateAuthKey
/**
* testValidateAuthKey method
*
* @access public
* @return void
*/
function testValidateAuthKey()
{
$authKey = Security::generateAuthKey();
$this->assertTrue(Security::validateAuthKey($authKey));
}