本文整理汇总了PHP中text::random方法的典型用法代码示例。如果您正苦于以下问题:PHP text::random方法的具体用法?PHP text::random怎么用?PHP text::random使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类text
的用法示例。
在下文中一共展示了text::random方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reset
public function reset()
{
if ($this->owner->logged_in()) {
url::redirect('/admin/testimonials/display');
}
$login_shell = new View('admin/login_shell');
$login_shell->content = new View('admin/reset');
if (empty($_POST)) {
die($login_shell);
}
$post = new Validation($_POST);
$post->pre_filter('trim');
$post->add_rules('email', 'required', 'valid::email');
# if Post is good, atttempt to log owner in.
if ($post->validate()) {
$owner = ORM::factory('owner')->find($_POST['email']);
if (!$owner->loaded) {
die('email does not have an account');
}
$pw = text::random('alnum', 8);
$owner->password = $pw;
$owner->save();
$replyto = 'unknown';
$body = "Your auto-generated password is: {$pw} \r\n" . "Change your password to something more appropriate by going here:\r\n" . "http://pluspanda.com/admin/account?old={$pw} \r\n\n" . "Thank you! - Jade from pluspanda";
# to do FIX THE HEADERS.
$subject = 'Your Pluspanda Password Has Been Reset =)';
$headers = "From: noreply@pluspanda.com \r\n" . "Reply-To: Jade \r\n" . 'X-Mailer: PHP/' . phpversion();
mail($_POST['email'], $subject, $body, $headers);
die('Please check your email for your new password!');
}
# error
$login_shell->content->alert = alerts::display(array('error' => 'Invalid Email or Password.'));
$login_shell->content->values = $_POST;
die($login_shell);
}
示例2: generate_challenge
/**
* Generates a new Captcha challenge.
*
* @return string The challenge answer
*/
public function generate_challenge()
{
// Complexity setting is used as character count
$text = text::random('distinct', max(1, Captcha::$config['complexity']));
// Complexity setting is used as character count
return $text;
}
示例3: save
public function save()
{
if (!$_POST) {
die;
}
$this->rsp = Response::instance();
if (!valid::email($_POST['email'])) {
$this->rsp->msg = 'Invalid Email!';
$this->rsp->send();
} elseif ($this->owner->unique_key_exists($_POST['email'])) {
$this->rsp->msg = 'Email already exists!';
$this->rsp->send();
}
$pw = text::random('alnum', 8);
$this->owner->email = $_POST['email'];
$this->owner->password = $pw;
$this->owner->save();
$replyto = 'unknown';
$body = "Hi there, thanks for saving your progess over at http://pluspanda.com \r\n" . "Your auto-generated password is: {$pw} \r\n" . "Change your password to something more appropriate by going here:\r\n" . "http://pluspanda.com/admin/account?old={$pw} \r\n\n" . "Thank you! - Jade from pluspanda";
# to do FIX THE HEADERS.
$subject = 'Your Pluspanda account information =)';
$headers = "From: welcome@pluspanda.com \r\n" . "Reply-To: Jade \r\n" . 'X-Mailer: PHP/' . phpversion();
mail($_POST['email'], $subject, $body, $headers);
# add to mailing list.
include Kohana::find_file('vendor/mailchimp', 'MCAPI');
$config = Kohana::config('mailchimp');
$mailchimp = new MCAPI($config['apikey']);
$mailchimp->listSubscribe($config['list_id'], $_POST['email'], '', 'text', FALSE, TRUE, TRUE, FALSE);
$this->rsp->status = 'success';
$this->rsp->msg = 'Thanks, Account Saved!';
$this->rsp->send();
}
示例4: create_token
protected function create_token()
{
// Token will always be 64 chars, as uniqid is 13 chars
$unique = uniqid();
$hard_to_guess = text::random('alnum', 51);
return $unique . $hard_to_guess;
}
示例5: token
public static function token()
{
if (($token = Session::instance()->get('csrf')) === FALSE) {
Session::instance()->set('csrf', $token = text::random('alnum', 16));
}
return $token;
}
示例6: token
/**
* Generates an returns a randon token for CSRF
* prevention
*
* @param bool $replace Whether to replace the current token
* @return string
*/
public static function token($replace = FALSE)
{
$token = Session::instance()->get(self::$_csrf_session_key);
if (!$token or $replace) {
// Generates a hash of variable length random alpha-numeric string
$token = hash('sha256', text::random('alnum', rand(25, 32)));
Session::instance()->set('csrf-token', $token);
}
return $token;
}
示例7: create_token
/**
* Finds a new unique token, using a loop to make sure that the token does
* not already exist in the database. This could potentially become an
* infinite loop, but the chances of that happening are very unlikely.
*
* @return string
*/
protected function create_token()
{
while (true) {
// Create a random token
$token = text::random('alnum', 32);
// Make sure the token does not already exist
if ($this->db->select('id')->where('token', $token)->get($this->table_name)->count() === 0) {
return $token;
}
}
}
示例8: reset_password
public function reset_password()
{
$str = text::random($type = 'alnum', $length = 10);
$this->password = $str;
$subject = "Your password has been reset for " . $_SERVER['HTTP_HOST'];
$message = "Your username is: " . $this->username . "\n\n";
$message .= "Your new password is: " . $str . "\n\n";
$message .= "You can reset it from the profile section of the user area";
$this->save();
email::send($this->email, 'admin@' . str_replace('www.', '', $_SERVER['HTTP_HOST']), $subject, $message, FALSE);
}
示例9: create_token
/**
* Finds a new unique token, using a loop to make sure that the token does
* not already exist in the database. This could potentially become an
* infinite loop, but the chances of that happening are very unlikely.
*
* @return string
*/
public function create_token()
{
while (TRUE) {
// Create a random token
$token = text::random('alnum', 32);
// Make sure the token does not already exist
if (!Jelly::select('user_token')->where('token', '=', $token)->count()) {
// A unique token has been found
return $token;
}
}
}
示例10: save
/**
* Overload saving to set the created time and to create a new token
* when the object is saved.
*/
public function save()
{
if ($this->loaded === FALSE) {
$this->created = time();
$this->token = text::random('alnum', 6);
} else {
$this->updated = time();
}
$this->url = str_replace('http://', '', strtolower($this->url));
#$this->body_edit = json_encode($this->body_edit);
return parent::save();
}
示例11: action_root
/**
* Create root user
*/
public function action_root()
{
echo '<h1>Root Account:</h1>';
$pass = text::random('alnum', 8);
$user = Sprig::factory('user')->values(array('username' => 'root', 'email' => 'root@domain.com', 'password' => $pass, 'password_confirm' => $pass, 'role' => 'admin'));
try {
$user->create();
echo 'Root user created, password is ' . $pass . '.';
} catch (Exception $e) {
echo 'Error creating root user.';
throw $e;
}
}
示例12: create_token
/**
* Finds a new unique token, using a loop to make sure that the token does
* not already exist in the database. This could potentially become an
* infinite loop, but the chances of that happening are very unlikely.
*
* @return string
*/
protected function create_token()
{
while (TRUE) {
// Create a random token
$token = text::random('alnum', 32);
// Make sure the token does not already exist
$count = DB::select('id')->where('token', '=', $token)->from($this->_table_name)->execute($this->_db)->count();
if ($count === 0) {
// A unique token has been found
return $token;
}
}
}
示例13: token
/**
* Get CSRF token
*
* @param mixed $id Custom token id, e.g. uid
* @param string $action Optional action
* @param integer $time
* @return string
*/
public static function token($id = '', $action = '', $time = 0)
{
// Get id string for token, could be uid or ip etc
if (!$id) {
$id = Input::instance()->ip_address();
}
// Get time to live
if (!$time) {
$time = ceil(time() / self::$ttl);
}
// Get session specific salt
if (!isset($_SESSION['csrf_secret'])) {
$_SESSION['csrf_secret'] = text::random('alnum', 16);
}
return md5($time . $_SESSION['csrf_secret'] . $id . $action);
}
示例14: index
/**
* Loads the landing page for this controller
*/
public function index()
{
// Set the current page
$this->template->this_page = "addons";
// Nexmo settings view
$this->template->content = new View('admin/addons/plugin_settings');
$this->template->content->title = Kohana::lang('nexmo.settings');
$this->template->content->settings_form = new View('nexmo/admin/nexmo_settings');
// Set up the form fields
$form = array('nexmo_api_key' => '', 'nexmo_api_secret' => '', 'nexmo_phone_no' => '');
// Get the current settings
$nexmo = ORM::factory('nexmo', 1)->loaded ? ORM::factory('nexmo', 1) : new Nexmo_Model();
// Has the form been submitted
if ($_POST) {
// Extract the data to be validated
$nexmo_data = arr::extract($_POST, 'nexmo_api_key', 'nexmo_api_secret', 'nexmo_phone_no');
Kohana::log('debug', Kohana::debug($nexmo_data));
// Invoke model validation on the data
if ($nexmo->validate($nexmo_data)) {
$nexmo->save();
}
}
// Check if authorization keys have been set
if (empty($nexmo->delivery_receipt_key)) {
// Key for authenticating delivery receipt not set, therefore generate
$nexmo->delivery_receipt_key = strtoupper(text::random('alnum', 10));
// Save
$nexmo->save();
}
if (empty($nexmo->inbound_message_key)) {
// Key for authenticating incoming messages not set, therefore generate
$nexmo->inbound_message_key = strtoupper(text::random('alnum', 10));
// Save
$nexmo->save();
}
// Set the form data
$form = array('nexmo_api_key' => $nexmo->nexmo_api_key, 'nexmo_api_secret' => $nexmo->nexmo_api_secret, 'nexmo_phone_no' => $nexmo->nexmo_phone_no);
// Set the content for the view
$this->template->content->settings_form->form = $form;
// Set the DLR and incoming message URLs
$this->template->content->settings_form->delivery_receipt_url = url::site() . 'nexmo/delivery/?key=' . $nexmo->delivery_receipt_key;
$this->template->content->settings_form->inbound_message_url = url::site() . 'nexmo/inbound/?key=' . $nexmo->inbound_message_key;
// Javascript header
$this->template->js = new View('nexmo/admin/nexmo_settings_js');
}
示例15: loadregister
public function loadregister($email)
{
if (!empty($this->warning)) {
$this->warning_msg($this->warning);
} else {
$view = new View('templates/' . $this->site['config']['TEMPLATE'] . '/register/dialog');
if ($this->session->get('input_data')) {
$this->template->content->indata = $this->session->get('input_data');
}
//assign random str
$this->mr['str_random'] = text::random('numeric', 6);
$this->mr['cus_email'] = $email;
$this->session->set_flash('sess_random', $this->mr['str_random']);
$view->mr = $this->mr;
$view->render(TRUE);
}
die;
}