本文整理汇总了PHP中generate_token函数的典型用法代码示例。如果您正苦于以下问题:PHP generate_token函数的具体用法?PHP generate_token怎么用?PHP generate_token使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了generate_token函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create_session
function create_session($request)
{
$raw_input = $request->getBody();
$content_type = explode(';', $request->type)[0];
switch ($content_type) {
case 'application/json':
$input_data = json_decode($raw_input, true);
break;
case 'application/x-www-form-urlencoded':
$input_data = array();
parse_str($raw_input, $input_data);
break;
default:
Util::output_errors_and_die('', 415);
}
if ($input_data === null) {
Util::output_errors_and_die('', 400);
}
set_empty_if_undefined($input_data['username_or_email']);
set_empty_if_undefined($input_data['password']);
$msg = new Messages($GLOBALS['locale'], '/signin');
try {
$model = new Model();
$user_data = $model->is_valid_user($input_data['username_or_email'], $input_data['password']);
if (!$user_data) {
Util::output_errors_and_die($msg->_('invalid-username-pw'), 403);
}
switch ($user_data['status']) {
case 'pending-activation':
Util::output_errors_and_die($msg->_('pending-activation'), 403);
break;
case 'pending-approval':
Util::output_errors_and_die($msg->_('pending-approval'), 403);
break;
case 'banned':
Util::output_errors_and_die($msg->_('banned'), 403);
break;
case 'active':
$token = generate_token($user_data);
$now = new DateTime('now');
$expires_at = clone $now;
$expires_at->add(new DateInterval('P7D'));
$model->insert_auth_token($user_data['user_id'], $token, $now, $expires_at);
http_response_code(201);
$output = array('token' => $token, 'expires_at' => $expires_at->format('Y-m-d H:i:s'));
setcookie('authToken', $token, $expires_at->getTimestamp(), '/', '', $secure = true, $httponly = true);
header('Content-Type: application/json');
echo my_json_encode($output);
die;
break;
}
} catch (DatabaseException $e) {
Util::output_errors_and_die($e->getMessage(), 503);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
}
示例2: createToken
private function createToken($app)
{
try {
$randToken = generate_token();
return Token::create(array('app_id' => $app->id, 'token' => $randToken));
} catch (\Exception $e) {
return $this->createToken($app);
}
}
示例3: cobalt_password_hash
function cobalt_password_hash($mode, $password, $username, &$salt = '', &$iteration = '', &$method = '')
{
require_once 'subclasses/system_settings.php';
$obj_settings = new system_settings();
if ($mode == 'RECREATE') {
$dbh = new data_abstraction();
$mysqli = $dbh->connect_db()->mysqli;
$clean_username = $mysqli->real_escape_string($username);
$dbh->set_table('user');
$dbh->set_fields('`salt`,`iteration`,`method`');
$dbh->set_where("`username`='{$clean_username}'");
$dbh->exec_fetch('single');
if ($dbh->num_rows == 1) {
extract($dbh->dump);
} else {
//No result found. We should produce fake data, so that the hashing process still takes place,
//mitigating probing / timing attacks
$salt = generate_token();
$method = cobalt_password_set_method();
if ($method == 'blowfish') {
$iteration = AUTH_BLOWFISH_COST_FACTOR;
} else {
$min = constant('AUTH_' . strtoupper($method) . '_MIN_ROUNDS');
$max = constant('AUTH_' . strtoupper($method) . '_MAX_ROUNDS');
if ($max < $min) {
$max = $min;
}
$iteration = mt_rand($min, $max);
echo $iteration . ' ' . $method . ' ' . $salt;
}
}
$dbh->close_db();
} elseif ($mode == 'NEW') {
$salt = generate_token();
$method = cobalt_password_set_method();
if ($method == 'blowfish') {
$iteration = AUTH_BLOWFISH_COST_FACTOR;
} else {
$min = constant('AUTH_' . strtoupper($method) . '_MIN_ROUNDS');
$max = constant('AUTH_' . strtoupper($method) . '_MAX_ROUNDS');
if ($max < $min) {
$max = $min;
}
$iteration = mt_rand($min, $max);
}
} else {
error_handler("Cobalt encountered an error during password processing.", "Cobalt Password Hash Error: Invalid mode specified.");
}
if ($method == 'blowfish') {
$digest = cobalt_password_hash_bcrypt($password, $salt, $iteration);
} elseif (in_array($method, cobalt_password_methods())) {
$digest = cobalt_password_hash_process($password, $salt, $iteration, $method);
} else {
error_handler("Cobalt encountered an error during password processing.", "Cobalt Password Hash Error: Invalid hash method specified.");
}
return $digest;
}
示例4: output
public function output()
{
$this->smarty->display("header.tpl");
$content = $this->smarty->fetch($this->template . ".tpl");
$content = preg_replace('/(<form\\W[^>]*\\bmethod=(\'|"|)POST(\'|"|)\\b[^>]*>)/i', '$1' . "\n" . generate_token(), $content);
if ($this->exitmsg) {
$content = $this->exitmsg;
}
echo $content;
$this->smarty->display("footer.tpl");
}
示例5: start_token_session
function start_token_session($userid)
{
global $mysqli;
invalidate_users_token($userid);
$token = generate_token();
$_SESSION["ip"] = $_SERVER["REMOTE_ADDR"];
$_SESSION["client"] = $_SERVER["HTTP_USER_AGENT"];
$_SESSION["token"] = $token;
$_SESSION["userid"] = $userid;
$mysqli->query("INSERT INTO `Sessions` (`Token`, `User-ID`, `IP`) VALUES ('{$token}', {$userid}, '" . $_SERVER['REMOTE_ADDR'] . "')");
}
示例6: send_token
function send_token()
{
$email = validate_email(@$_POST['email']);
if (email_overlap($email)) {
echo "email overlap";
die;
}
$mail = new PHPMailer();
//实例化
$mail->IsSMTP();
// 启用SMTP
$mail->Host = $GLOBALS['smtp_server'];
//SMTP服务器 以163邮箱为例子
$mail->Port = $GLOBALS['smtp_server_port'];
//邮件发送端口
$mail->SMTPAuth = true;
//启用SMTP认证
$mail->CharSet = "UTF-8";
//字符集
$mail->Encoding = "base64";
//编码方式
$mail->Username = $GLOBALS['smtp_user_mail'];
//你的邮箱
$mail->Password = $GLOBALS['smtp_user_pass'];
//你的密码
$mail->Subject = "NutLab SS Token";
//邮件标题
$mail->From = $GLOBALS['smtp_user_mail'];
//发件人地址(也就是你的邮箱)
$mail->FromName = "NutLab";
//发件人姓名
$address = $email;
//收件人email
$mail->AddAddress($address, "Dear");
//添加收件人(地址,昵称)
$mail->IsHTML(true);
//支持html格式内容
$token = generate_token();
$mail->Body = "感谢您在我站注册了新帐号。<br/><br/>你的验证码为" . $token;
//邮件主体内容
if (!$mail->Send()) {
echo "token sending fail:" . $mail->ErrorInfo;
echo "token sending fail";
} else {
echo "token sending success";
}
$count = count($GLOBALS['DB']->query("SELECT * FROM user WHERE email=? ", array($email)));
if ($count > 0) {
$result = $GLOBALS['DB']->query("UPDATE user SET token=? WHERE email=?", array($token, $email));
} else {
$result = $GLOBALS['DB']->query("INSERT INTO user (email,pass,passwd,u,d,transfer_enable,port,enable,activated,token) VALUES (?,'','','0','0','0',?,'0','0',?)", array($email, generate_port(), $token));
}
}
示例7: add
public static function add($first_name, $last_name, $phone, $email, $password, $zipcode, $referral_code = '', $device_token = '', $device_type = 'web', $membership_type = 'Member')
{
$user = new User();
$user_credit = new UserCredit();
$user->first_name = $first_name;
$user->last_name = $last_name;
$user->phone = $phone;
$user->email = $email;
$user->referred_by = 0;
$user->token = generate_token();
$user->token_expiry = generate_expiry() / 10;
$user->social_id = 0;
if ($device_type != 'web') {
$user->device_token = $device_token;
} else {
$user->device_token = '';
}
$user->device_type = $device_type;
$user->image_url = '';
$user->total_referrals = 0;
$user->remember_token = '';
$user_credit->earned = 0;
$user_credit->spent = 0;
if ($referral_code != '') {
$referrer = User::where('referral_code', $referral_code)->first();
if ($referrer) {
$user->referred_by = $referrer->id;
$user_credit->earned = 10;
// add credits to referrer
$referrer_credit = UserCredit::where('user_id', $referrer->id)->first();
$referrer_credit->earned += 5;
$referrer_credit->spent = 0;
$referrer_credit->save();
$temp_user = User::find($referrer->id);
$temp_user->total_referrals += 1;
$temp_user->save();
}
}
$user->password = Hash::make($password);
$user->membership_type = $membership_type;
$user->zipcode = $zipcode;
$user->referral_code = generate_referral_code($first_name, $last_name);
if ($membership_type == 'Member') {
$user->membership_ends_on = "2100-01-01";
} else {
$user->membership_ends_on = date('Y-m-d', strtotime('+1 years'));
}
$user->save();
$user_credit->user_id = $user->id;
$user_credit->save();
return $user;
}
示例8: make_token
function make_token()
{
// Temporary: purge tokens more often
// Tokens are cleared on GW communication,
// but there is no gateway right now
clear_old_tokens();
$db = Flight::db();
$token = generate_token();
$stmt = $db->prepare('INSERT INTO tokens (token) VALUES (:token)');
$stmt->bindParam(':token', $token);
$stmt->execute();
return $token;
}
示例9: replace_forms
function replace_forms($form_data_html)
{
$count = preg_match_all("/<form(.*?)>(.*?)<\\/form>/is", $form_data_html, $matches, PREG_SET_ORDER);
if (is_array($matches)) {
foreach ($matches as $m) {
if (strpos($m[1], "nocsrf") !== false) {
continue;
}
$name = "CSRFGuard_" . mt_rand(0, mt_getrandmax());
$token = generate_token($name);
$form_data_html = str_replace($m[0], "<form{$m[1]}>\n<input type='hidden' name='CSRFName' value='{$name}' />\n<input type='hidden' name='CSRFToken' value='{$token}' />{$m[2]}</form>", $form_data_html);
}
}
return $form_data_html;
}
示例10: generate_token
function generate_token($username, $deep = 0)
{
global $db;
$deep++;
if ($deep > 3) {
return false;
}
$token_string = generate_string(64);
// 检测有效性
$token = $db->get('token', array('token', 'username', 'expired_time'), array('AND' => array('token' => $token_string, 'expired_time[>]' => time())));
if ($token) {
return generate_token($username, $deep);
} else {
$result = $db->insert('token', array('token' => $token_string, 'username' => $username, 'expired_time' => time() + 3600 * 2));
$active = $db->insert('active', array('content' => "登录创建 token:{$token_string} 经过 {$deep} 次", 'username' => $username, 'time' => date('Y-m-d H:i:s', time())));
return $token_string;
}
}
示例11: widget_my_notes
function widget_my_notes($vars)
{
$title = "My Notes";
$mynotes = get_query_val("tbladmins", "notes", array("id" => $vars['adminid']));
$content = '
<script>
function widgetnotessave() {
$.post("index.php", { action: "savenotes", notes: $("#widgetnotesbox").val(), token: "' . generate_token('plain') . '" });
$("#widgetnotesconfirm").slideDown().delay(2000).slideUp();
}
</script>
<div align="center">
<div id="widgetnotesconfirm" style="display:none;margin:0 0 5px 0;padding:5px 20px;background-color:#DBF3BA;font-weight:bold;color:#6A942C;">Notes Saved Successfully!</div>
<textarea id="widgetnotesbox" style="width:95%;height:100px;">' . $mynotes . '</textarea>
<input type="button" value="Save Notes" onclick="widgetnotessave()" />
</div>
';
return array('title' => $title, 'content' => $content);
}
示例12: openform
function openform($form_name, $form_id, $method, $action, $array = false)
{
global $defender;
if (!is_array($array)) {
$class = '';
$enctype = '';
$downtime = 10;
$notice = 1;
} else {
$class = array_key_exists('class', $array) && $array['class'] ? $array['class'] : '';
$enctype = array_key_exists('enctype', $array) && $array['enctype'] == 1 ? 1 : 0;
$downtime = array_key_exists('downtime', $array) && isnum($array['downtime']) ? $array['downtime'] : 10;
$notice = array_key_exists('notice', $array) && isnum($array['notice']) ? $array['notice'] : 1;
}
$html = "<form name='" . $form_name . "' id='" . $form_id . "' method='" . $method . "' action='" . $action . "' class='" . (defined('FUSION_NULL') ? 'warning' : '') . " {$class}' " . ($enctype ? "enctype='multipart/form-data'" : '') . " >\n";
$html .= generate_token($form_name, $downtime);
if (defined('FUSION_NULL') && $notice) {
echo $defender->showNotice();
}
return $html;
}
示例13: __construct
/**
* Constructor.
*
* @param array $vars "vars" array from WHCMS.
*/
public function __construct($vars = array())
{
global $templates_compiledir, $customadminpath, $module, $_LANG, $CONFIG;
// Create smarty
$this->view = new \Smarty();
$this->view->template_dir = ROOTDIR . '/modules/addons/' . $module . '/templates/';
$this->view->compile_dir = $templates_compiledir;
// Assing WHMCS system params
$this->view->assign('_LANG', $_LANG);
$this->view->assign('_CONFIG', $CONFIG);
$this->view->assign('csrfToken', generate_token('plain'));
// Assing our module params
$this->vars = $vars;
$this->view->assign('vars', $this->vars);
$this->view->assign('customadminpath', $customadminpath);
$this->modulelink = '/' . $customadminpath . '/addonmodules.php?module=' . $module;
$this->view->assign('modulelink', $this->modulelink);
if (isset($_REQUEST['action'])) {
$this->action = $_REQUEST['action'];
}
$this->view->assign('action', $this->action);
}
示例14: widget_my_notes
function widget_my_notes($vars)
{
global $_ADMINLANG;
$title = "My Notes";
$mynotes = get_query_val("tbladmins", "notes", array("id" => $vars['adminid']));
$content = '
<script>
function widgetnotessave() {
$.post("index.php", { action: "savenotes", notes: $("#widgetnotesbox").val(), token: "' . generate_token('plain') . '" });
$("#widgetnotesconfirm").slideDown().delay(2000).slideUp();
}
</script>
<div id="widgetnotesconfirm" style="display:none;margin:0 0 5px 0;padding:5px 20px;background-color:#DBF3BA;font-weight:bold;color:#6A942C;">Notes Saved Successfully!</div>
<form>
<textarea id="widgetnotesbox" style="height:100px;" class="form-control">' . $mynotes . '</textarea>
<div class="widget-footer">
<input type="reset" value="' . $_ADMINLANG['global']['cancel'] . '" class="btn btn-default btn-sm" /> <input type="button" value="Save Notes" onclick="widgetnotessave()" class="btn btn-info btn-sm" />
</div>
</form>
';
return array('title' => $title, 'content' => $content);
}
示例15: create_session
function create_session($expire_secs = NULL, $login_id = NULL, $network_address = NULL)
{
global $dbconn;
global $auth_settings;
// Check parameters
// $network_address is mandatory, fail immediately if not set
if (is_null($network_address)) {
$network_address = $_SERVER['REMOTE_ADDR'];
}
if (strlen($network_address) < 4) {
return FALSE;
}
// Login ID is mandatory
if (is_numeric($login_id) === FALSE || $login_id < 0 || $login_id == NULL) {
return FALSE;
}
if (is_null($expire_secs) || $expire_secs < $auth_settings['session_expire_default']) {
$expire_secs = $auth_settings['session_expire_default'];
}
$session_key = generate_token();
$csrf_token = generate_token();
$create_time = time();
$expire_time = $create_time + $expire_secs;
// Add or update the session in the database
$sql = "INSERT INTO sessions (\n\t\t\tlogin_id,\n\t\t\tsession_key, csrf_token, network_address,\n\t\t\tcreate_time, expire_time\n\t\t) VALUES (\n\t\t\t:li, :sk, :csrf, :na,\n\t\t\t:ct, :et\n\t\t)\n\t\tON DUPLICATE KEY UPDATE\n\t\tlogin_id = :li,\n\t\tsession_key = :sk,\n\t\tcsrf_token = :csrf,\n\t\tnetwork_address = :na,\n\t\tcreate_time = :ct,\n\t\texpire_time = :et";
$stmt = $dbconn->prepare($sql);
$stmt->bindParam(':li', $login_id, PDO::PARAM_INT);
$stmt->bindParam(':sk', $session_key, PDO::PARAM_STR);
$stmt->bindParam(':csrf', $csrf_token, PDO::PARAM_STR);
$stmt->bindParam(':na', $network_address, PDO::PARAM_STR);
$stmt->bindParam(':ct', $create_time, PDO::PARAM_INT);
$stmt->bindParam(':et', $expire_time, PDO::PARAM_INT);
// Catch any failure to create a session
if ($stmt->execute() == FALSE) {
return FALSE;
}
set_auth_cookie($session_key, $expire_time, $domain);
return TRUE;
}