• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP generateRandomString函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中generateRandomString函数的典型用法代码示例。如果您正苦于以下问题:PHP generateRandomString函数的具体用法?PHP generateRandomString怎么用?PHP generateRandomString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了generateRandomString函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: generate

 /**
  * 
  * Generate code using given parameters
  * @param array $paramsArray
  */
 public function generate(OTCConfig $config = null)
 {
     if ($config === null) {
         $config = new OTCConfig();
     }
     $paramsArray = $config->paramsArray;
     if (isset($paramsArray['r'])) {
         throw new RuntimeException("Key 'r' is not allowed to be present in \$paramsArray. Please remove or rename it.");
     }
     $paramsArray['r'] = generateRandomString(12);
     $keyValArray = array();
     $keysUniqueCheckArray = array();
     foreach ($paramsArray as $key => $value) {
         if (preg_match("/[:;]/", $key) or preg_match("/[:;]/", $value)) {
             throw new RuntimeException("Invalid characters in \$paramsArray. No ; or : characters are allowed!");
         }
         if (in_array($key, $keysUniqueCheckArray)) {
             throw new RuntimeException("Duplicate key '{$key}' in \$paramsArray. It's not allowed!");
         }
         array_push($keysUniqueCheckArray, $key);
         array_push($keyValArray, "{$key}:{$value}");
     }
     $stringToEncrypt = implode(";", $keyValArray);
     $encryptedString = AES256::encrypt($stringToEncrypt);
     if (strlen($encryptedString) > static::CODE_MAX_LENGTH) {
         throw new RuntimeException("Resulting code is longer than allowed " . static::CODE_MAX_LENGTH . " characters!");
     }
     $this->query->exec("INSERT INTO `" . Tbl::get('TBL_ONE_TIME_CODES') . "` \n\t\t\t\t\t\t\t\t\t(`code`, `multi`, `usage_limit`, `not_cleanable`, `valid_until`) \n\t\t\t\t\t\t\t\t\tVALUES(\t'{$encryptedString}', \n\t\t\t\t\t\t\t\t\t\t\t'" . ($config->multiUse ? '1' : '0') . "',\n\t\t\t\t\t\t\t\t\t\t\t" . ($config->usageLimit ? "'{$config->usageLimit}'" : "NULL") . ",\n\t\t\t\t\t\t\t\t\t\t\t'" . ($config->notCleanable ? '1' : '0') . "',\n\t\t\t\t\t\t\t\t\t\t\t" . ($config->validityTime ? "FROM_UNIXTIME(UNIX_TIMESTAMP(NOW()) + {$config->validityTime})" : 'NULL') . ")");
     return $encryptedString;
 }
开发者ID:alexamiryan,项目名称:stingle,代码行数:35,代码来源:OneTimeCodes.class.php


示例2: update_categories

 public function update_categories($images)
 {
     if (empty($this->input->post('status'))) {
         $status = 0;
     } else {
         $status = 1;
     }
     $this->load->helper('rand_helper');
     foreach ($images as $key => $value) {
         if (!empty($value['name'])) {
             if (!empty($this->input->post('old_' . $key))) {
                 unlink(FCPATH . $this->input->post('old_' . $key));
             }
             $randomString = generateRandomString(14);
             $db_img_name[$key] = 'assets/uploads/system/images/catid_' . $this->input->post('id') . '_' . $randomString . '-' . $this->changeName($value['name']);
         } else {
             $db_img_name[$key] = $this->input->post('old_' . $key);
         }
         if ($this->input->post('delete_' . $key)) {
             unlink(FCPATH . $this->input->post('delete_' . $key));
             $db_img_name[$key] = '';
         }
         move_uploaded_file($value["tmp_name"], FCPATH . $db_img_name[$key]);
     }
     $categories_update_data = array('status' => $status, 'perma_link' => $this->input->post('perma_link'), 'perma_active' => $this->input->post('perma_active'), 'name' => $this->input->post('name'), 'description' => $this->input->post('description'), 'image' => $db_img_name['image'], 'banner' => $db_img_name['banner'], 'queue' => $this->input->post('queue'), 'list_layout' => $this->input->post('list_layout'), 'meta_description' => $this->input->post('meta_description'), 'meta_keyword' => $this->input->post('meta_keyword'), 'meta_title' => $this->input->post('meta_title'));
     $this->db->set($categories_update_data);
     $this->db->where('id', $this->input->post('id'));
     $this->db->update('categories');
 }
开发者ID:huseyindol,项目名称:ci-projects,代码行数:29,代码来源:Categories_Model.php


示例3: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request, MemberInputtedMailer $mailer)
 {
     $this->validate($request, ['first_name' => 'required', 'last_name' => 'required', 'email' => 'required|email|unique:users']);
     $user = new User();
     $user->first_name = $request->get('first_name');
     $user->last_name = $request->get('last_name');
     $user->street_address = $request->get('address1');
     $user->city = $request->get('city');
     $user->state = $request->get('state_province');
     $user->zip = $request->get('postal_code');
     $user->phone_number = $request->get('phone');
     $user->email = $request->get('email');
     $user->membership_expires = date('Y-m-d', strtotime($request->get('membership_expires')));
     $user->birthday = date('Y-m-d', strtotime($request->get('birthday')));
     $user->anniversary = date('Y-m-d', strtotime($request->get('anniversary')));
     $user->plan_id = $request->get('plan_id');
     $user->temp_password = 1;
     $randomString = generateRandomString();
     $user->password = bcrypt($randomString);
     $user->save();
     $user->random_string = $randomString;
     $mailer->forward($user);
     Flash::success('This member was successfully added to the database.');
     return redirect('admin/membership');
 }
开发者ID:scotthummel,项目名称:lambdaphx,代码行数:31,代码来源:MembershipController.php


示例4: insertKey

function insertKey($email, $IME, $deviceId, $type, $payerId, $dayLimit, $price)
{
    $keyCreate = generateRandomString();
    //231
    while (true) {
        if (checkKeyExist($keyCreate)) {
            $keyCreate = generateRandomString();
        } else {
            break;
        }
    }
    $conn = getConnection();
    $keygen = null;
    //check key exits
    $query = sprintf("insert into %s(email,IME_CODE,Device_id,Type,CreateDate,Key_Code,PayerId,DateLimit,Price) values('%s','%s','%s',%d,now(),'%s','%s',DATE_ADD(now(),INTERVAL %d DAY ),%f)", KEY_TABLE, mysql_real_escape_string($email), mysql_real_escape_string($IME), mysql_real_escape_string($deviceId), mysql_real_escape_string($type), mysql_real_escape_string($keyCreate), mysql_real_escape_string($payerId), $dayLimit, $price);
    $result = mysql_query($query, $conn);
    if (!$result) {
        $errMsg = "Error: " . mysql_error($conn);
        mysql_close($conn);
        throw new Exception("Error Processing Request:" . $errMsg, 1);
    }
    $recordId = mysql_insert_id($conn);
    mysql_close($conn);
    if ($recordId > 0) {
        return $keyCreate;
    }
    return null;
}
开发者ID:kenpi04,项目名称:apidemo,代码行数:28,代码来源:key.php


示例5: generate

 /**
  * 
  * Generate code using given parameters
  * @param array $paramsArray
  */
 public function generate(OTCConfig $config = null)
 {
     if ($config === null) {
         $config = new OTCConfig();
     }
     $paramsArray = $config->paramsArray;
     if (isset($paramsArray['r'])) {
         throw new RuntimeException("Key 'r' is not allowed to be present in \$paramsArray. Please remove or rename it.");
     }
     $paramsArray['r'] = generateRandomString(12);
     $keyValArray = array();
     $keysUniqueCheckArray = array();
     foreach ($paramsArray as $key => $value) {
         if (preg_match("/[:;]/", $key) or preg_match("/[:;]/", $value)) {
             throw new RuntimeException("Invalid characters in \$paramsArray. No ; or : characters are allowed!");
         }
         if (in_array($key, $keysUniqueCheckArray)) {
             throw new RuntimeException("Duplicate key '{$key}' in \$paramsArray. It's not allowed!");
         }
         array_push($keysUniqueCheckArray, $key);
         array_push($keyValArray, "{$key}:{$value}");
     }
     $stringToEncrypt = implode(";", $keyValArray);
     $encryptedString = AES256::encrypt($stringToEncrypt);
     if (strlen($encryptedString) > static::CODE_MAX_LENGTH) {
         throw new RuntimeException("Resulting code is longer than allowed " . static::CODE_MAX_LENGTH . " characters!");
     }
     $qb = new QueryBuilder();
     $qb->insert(Tbl::get('TBL_ONE_TIME_CODES'))->values(array("code" => $encryptedString, "multi" => $config->multiUse ? 1 : 0, "usage_limit" => $config->usageLimit ? $config->usageLimit : new Literal("NULL"), "not_cleanable" => $config->notCleanable ? 1 : 0, "valid_until" => $config->validityTime ? new Func('FROM_UNIXTIME', $qb->expr()->sum(new Func('UNIX_TIMESTAMP', new Func('NOW')), $config->validityTime)) : new Literal("NULL")));
     $this->query->exec($qb->getSQL());
     return $encryptedString;
 }
开发者ID:Welvin,项目名称:stingle,代码行数:37,代码来源:OneTimeCodes.class.php


示例6: dummyUser

function dummyUser($db)
{
    $pass = hashPassword("admin");
    $key = generateRandomString();
    $sql = "INSERT INTO users VALUES (NULL,'admin','{$pass}','{$key}',NULL);";
    execSql($db, $sql, "add admin user");
}
开发者ID:acyuta,项目名称:simple_php_api_net,代码行数:7,代码来源:setupDB.php


示例7: recover

 function recover()
 {
     $return = array("rpta" => false, "message" => "Ingrese correo electronico.");
     $dataPost = $this->input->post();
     $notfind = false;
     if (isset($dataPost['data'])) {
         $rptaTmp = $this->recoverpass->checkmail($dataPost['data']);
         //var_dump("<pre>",$rptaTmp);exit;
         if ($rptaTmp['rpta'] == true) {
             while ($notfind == false) {
                 $string = generateRandomString();
                 $tmp = $this->recoverpass->Find($string);
                 // se comprueba que este codigo no exista en la bd
                 $notfind = $tmp['rpta'];
             }
             $arr = array("email" => $dataPost['data'], "generatecode" => $string);
             $message = "<p>Hemos recibido la solicitud de restaurar su contraseña.</p>" . "<p>Si usted ha solicitado este cambio de contraseña por favor de click <a href='" . site_url('Recoverpass/changePassMail') . "/" . $string . "'>AQUI</a> </p>" . "<p>Caso contrario, por favor ingrese a <a href='http://www.lifeleg.com/'>www.lifeleg.com</a>, y cambie su contraseña.</p>" . "<p>GRACIAS, por pertenecer a nuestra familia, seguiremos trabajando para ofrecerle lo mejor.</p>";
             $rptamail = send_email("Restaurar contraseña", $message, $dataPost['data'], false);
             if ($rptamail == true) {
                 $arr = array("email" => $dataPost['data'], "generatecode" => $string);
                 $this->recoverpass->insertRecover($arr);
                 $return['rpta'] = true;
                 $return['message'] = "Correo enviado correctamente, por favor ingresa a tu bandeja y sigue las instrucciones, Gracias!";
             }
         } else {
             $return['message'] = "E-mail no registrado, verifique y vuelva a intentarlo por favor.";
         }
     }
     echo json_encode($return);
 }
开发者ID:carloz192,项目名称:lifeleg,代码行数:30,代码来源:Recoverpass.php


示例8: randomID

function randomID($location)
{
    global $conn;
    $x = 0;
    $result = true;
    while ($result) {
        $randomString = generateRandomString(16);
        //generera ett random id på 16 tecken och kolla så att det inte är taget. om taget
        $sql = "SELECT id FROM `users` WHERE `id` = '{$randomString}';";
        /*
        	select 1 
        	from (
        	    select username as username from tbl1
        	    union all
        	    select username from tbl2
        	    union all
        	    select username from tbl3
        	) a
        	where username = 'someuser'
        */
        $result = $conn->query($sql);
        if ($result->num_rows == 0) {
            var_dump($randomString);
            $result = false;
        } else {
            echo "{$randomString}<br>";
        }
        $x++;
    }
}
开发者ID:TheSwedishScout,项目名称:dethandeengrej,代码行数:30,代码来源:getData.php


示例9: blog_update

 function blog_update($images)
 {
     $this->load->helper('rand_helper');
     $blog_update_data = array('pages_type' => $this->input->post('pages_type'), 'perma_link' => $this->input->post('perma_link'), 'perma_active' => $this->input->post('perma_active'), 'quick_link' => $this->input->post('quick_link'), 'blog_comments_enable' => $this->input->post('blog_comments_enable'), 'title' => $this->input->post('title'), 'content' => $this->input->post('content', FALSE), 'list_title' => $this->input->post('list_title'), 'list_content' => $this->input->post('list_content'), 'meta_description' => $this->input->post('meta_description'), 'meta_keyword' => $this->input->post('meta_keyword'), 'meta_title' => $this->input->post('meta_title'));
     $this->db->set($blog_update_data);
     $this->db->where('id', $this->input->post('id'));
     $this->db->update('blog');
     foreach ($images as $key => $value) {
         if (!empty($value['name'])) {
             if (!empty($this->input->post('old_' . $key))) {
                 unlink(FCPATH . $this->input->post('old_' . $key));
             }
             $randomString = generateRandomString(14);
             $db_img_name[$key] = 'assets/uploads/system/images/' . $key . '_' . $randomString . '-' . $this->changeName($value['name']);
         } else {
             $db_img_name[$key] = $this->input->post('old_' . $key);
         }
         if ($this->input->post('delete_' . $key)) {
             unlink(FCPATH . $this->input->post('delete_' . $key));
             $db_img_name[$key] = '';
         }
         move_uploaded_file($value["tmp_name"], FCPATH . $db_img_name[$key]);
         $blog_update_image = array('list_image' => $db_img_name[$key]);
         $this->db->set($blog_update_image);
         $this->db->where('id', $this->input->post('id'));
         $this->db->update('blog');
     }
 }
开发者ID:huseyindol,项目名称:ci-projects,代码行数:28,代码来源:Blog_Model.php


示例10: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  Request $request
  * @return Response
  */
 public function store(Request $request, PropertyInterface $property, booking $booking, serviceBooking $serviceBooking, service $service)
 {
     $ownerId = $property->findOrFail($request->get('propertyId'))->owner->id;
     $orderRef = generateRandomString();
     $invoiceData = ['serviceId' => $request->get('selectedServiceIds'), 'payee_id' => $request->user()->id, 'seller_id' => $ownerId, 'orderRef' => $orderRef, 'amount' => $request->get('overallTotal')];
     $newInvoice = $this->invoices->create($invoiceData);
     $bookingData = ['user_id' => $request->user()->id, 'property_id' => $request->get('propertyId'), 'invoice_id' => $newInvoice->id, 'price' => $request->get('nightRate'), 'checkInDate' => convertToCarbonDate($request->get('checkInDate')), 'checkOutDate' => convertToCarbonDate($request->get('checkOutDate'))];
     $booking->create($bookingData);
     if (count($request->get('selectedServiceIds')) > 0) {
         $serviceData = [];
         foreach ($request->get('selectedServiceIds') as $serviceId) {
             $theService = $service->findOrFail($serviceId);
             $serviceData['service_id'] = $serviceId;
             $serviceData['user_id'] = $request->user()->id;
             if ($theService->type == 'onceoff') {
                 $serviceData['quantity'] = 1;
             }
             if ($theService->type == 'daily') {
                 $serviceData['quantity'] = $bookingData['checkOutDate']->diffInDays($bookingData['checkInDate']);
             }
             $serviceData['invoice_id'] = $newInvoice->id;
         }
         $serviceBooking->create($serviceData);
     }
     return ['response' => 'completed', 'orderRef' => $orderRef, 'propertyId' => $request->get('propertyId')];
 }
开发者ID:xavierauana,项目名称:avaluestay,代码行数:32,代码来源:InvoicesController.php


示例11: smarty_function_rand

/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */
function smarty_function_rand($params, &$smarty)
{
    $length = null;
    $type = null;
    extract($params);
    return generateRandomString($length, $type);
}
开发者ID:Welvin,项目名称:stingle,代码行数:12,代码来源:function.rand.php


示例12: generateCode

 public function generateCode($id)
 {
     $reg_code = '';
     $code = generateRandomString(8) . $id;
     $reg_code = substr($code, 2, 8);
     return $reg_code;
 }
开发者ID:nguyenvanvu,项目名称:slu,代码行数:7,代码来源:AccountForm.php


示例13: createAccount

function createAccount($userInfo)
{
    //echo('creating...');
    if (!isset($userInfo['email'])) {
        $resp = array("status" => "fail", "reason" => "please send the email to create account");
        return $resp;
    }
    if (!isset($userInfo['passwd'])) {
        $resp = array("status" => "fail", "reason" => "please send password to create account");
        return $resp;
    }
    $userInfo['userId'] = generateRandomString();
    $unencrypted = $userInfo['passwd'];
    $userInfo['passwd'] = md5($userInfo['passwd']);
    $email = $userInfo['email'];
    $exists = dbMassData("SELECT * FROM users WHERE email = '{$email}'");
    if ($exists != NULL) {
        $account = loginUser($email, $unencrypted);
        return $account;
    }
    $passwd = $userInfo['passwd'];
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    dbQuery("INSERT INTO users (email, passwd, ip) VALUES('{$email}', '{$passwd}', '{$ip}')");
    //$resp = array("status"=>"success", "reason"=>"account created");
    //return $resp;
    $account = loginUser($email, $unencrypted);
    return $account;
}
开发者ID:Blaeg,项目名称:BitcoinTrader,代码行数:28,代码来源:index.php


示例14: run

function run()
{
    if (!isset($_POST["pw"])) {
        return;
    }
    if (md5($_POST["pw"]) !== $md5pw) {
        die("<!DOCTYPE html><html><head><meta charset=utf-8> <title> Add Song! </title> </head> <body> Wrong Password! </body> </html>");
    }
    $x = time() . "_" . generateRandomString(32);
    //hopefully not duplicate :)
    mkdir($x);
    $target_dir = $x . "/";
    $fp = fopen("songlist", "a");
    fwrite($fp, $x . "\n");
    fclose($fp);
    $fp = fopen($target_dir . "songdata", "w");
    echo htmlentities($_POST["music_name"], ENT_QUOTES, "UTF-8");
    echo "<br/>";
    echo htmlentities($_POST["composer"], ENT_QUOTES, "UTF-8");
    fwrite($fp, base64_encode(htmlentities($_POST["music_name"], ENT_QUOTES, "UTF-8")));
    fwrite($fp, "\n");
    fwrite($fp, base64_encode(htmlentities($_POST["composer"], ENT_QUOTES, "UTF-8")));
    fclose($fp);
    doFileUpload($target_dir . "song.mp3", $_FILES["mp3"]);
    doFileUpload($target_dir . "song.lrc", $_FILES["lrc"]);
    doFileUpload($target_dir . "folder.png", $_FILES["png"]);
}
开发者ID:ho94949,项目名称:musicplayer,代码行数:27,代码来源:uploadSong.php


示例15: create_banklink

function create_banklink($token, $amount, $description)
{
    $db = Db::getInstance()->getConnection();
    $banklink = generateRandomString();
    $query = "INSERT INTO banklinks (banklink, user_id, amount, description, timestamp)\n                    VALUES ('" . $banklink . "', (SELECT user_id FROM tokens WHERE token= '" . mysqli_real_escape_string($db, $token) . "'), {$amount}, '{$description}', NOW())";
    $db->query($query) or die("Couldn't create banklink");
    return $banklink;
}
开发者ID:kadrim1,项目名称:net_bank,代码行数:8,代码来源:api_operations.php


示例16: n2GoApiActivation

function n2GoApiActivation()
{
    global $wp_rewrite;
    add_filter('query_vars', 'n2goAddQueryVars');
    add_filter('rewrite_rules_array', 'n2GoApiRewrites');
    $wp_rewrite->flush_rules();
    $authKey = generateRandomString();
    get_option('n2go_apikey', null) !== null ? update_option('n2go_apikey', $authKey) : add_option('n2go_apikey', $authKey);
}
开发者ID:newsletter2go,项目名称:newsletter2go-wordpress-plugin,代码行数:9,代码来源:newsletter2go.php


示例17: generateCodeID

 public function generateCodeID($id)
 {
     var_dump($id);
     exit;
     $reg_code = '';
     $code = generateRandomString(8) . $id;
     $reg_code = substr($code, 2, 8);
     return $reg_code;
 }
开发者ID:nguyenvanvu,项目名称:slu,代码行数:9,代码来源:SeminarForm.php


示例18: passwordCheck

function passwordCheck($password)
{
    $pwcheck = mysql_query("SELECT `id` FROM `classes` WHERE `password` = '{$password}'");
    if (mysql_num_rows($pwcheck) != 0) {
        $password = generateRandomString();
        passwordCheck();
        return;
    }
}
开发者ID:keelandaye,项目名称:equiz,代码行数:9,代码来源:newclass.php


示例19: findFreeRandomUsername

 /**
  * Function get random username
  * @param string $prefix is name of current external plugin
  * @return string 
  */
 private static function findFreeRandomUsername($prefix)
 {
     $um = Reg::get(ConfigManager::getConfig("Users", "Users")->Objects->UserManager);
     $possibleUsername = $prefix . "_" . generateRandomString(6);
     if (!$um->isLoginExists($possibleUsername, 0)) {
         return $possibleUsername;
     } else {
         return static::findFreeRandomUsername($prefix);
     }
 }
开发者ID:Welvin,项目名称:stingle,代码行数:15,代码来源:ExternalUserManager.class.php


示例20: exchange_point

 function exchange_point($coupon_id)
 {
     $this->load->helper("keygen");
     $uid = $this->get_user_id();
     $insert = array("user_id" => $uid, "coupon_id" => $coupon_id, "coupon_code" => generateRandomString());
     $this->model->insert_row($insert, "user_coupon");
     $point = $this->model->get_value("points_needed", "coupons", array("id" => $coupon_id));
     $this->subtract_point($uid, $point);
     redirect("user/view_coupons/" . $uid);
 }
开发者ID:jerwinner,项目名称:hackclimate2015,代码行数:10,代码来源:user.php



注:本文中的generateRandomString函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP generateRequestToken函数代码示例发布时间:2022-05-15
下一篇:
PHP generateQuestionMarks函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap