本文整理汇总了PHP中rand_string函数的典型用法代码示例。如果您正苦于以下问题:PHP rand_string函数的具体用法?PHP rand_string怎么用?PHP rand_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rand_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: j_email
public function j_email()
{
// 如果
if (isset($_POST['em'])) {
$email = $_POST['em'];
$account_model = D('Account');
// 证明已经注册过
if ($account_model->judge_account_id_isset($email)) {
Response::show('-101', '该邮箱已经被注册!');
} else {
// 发送给用户的信息
$rand_string = strtolower(rand_string());
$title = '欢迎您注册!么么哒。';
$content = '您好,您的注册验证码是 : ' . $rand_string . ' !, 如果不是本人操作,请忽略!';
$Memcached = Memcached::getInstance();
// 暂时不加密了。
$Memcached->set($email, $rand_string);
if (SendMail($email, $title, $content) === true) {
Response::show('200', '已经发送验证码,请注意查收!');
} else {
Log::write('发送验证码失败,to [--' . $email . '--]', 'WARN');
Response::show('-102', '邮件发送失败,未知原因!');
}
}
}
Response::show('-103', '数据丢失!');
}
示例2: register
public function register()
{
$model = D('Member');
if (false === $model->create()) {
//错误提示
$msg['error_code'] = 8002;
$msg['notice'] = $model->getError();
echo json_encode($msg);
exit;
}
$data['tel'] = $_POST['tel'];
$data['salt'] = $salt = rand_string(6, -1);
$psw = md5($_POST['password'] . $salt . $salt[1]);
$data['password'] = $psw;
$mid = $model->add($data);
if ($mid) {
$msg['error_code'] = 0;
$msg['notice'] = '注册成功';
//生成token
$token = create_token($mid, $salt);
$vo['id'] = $mid;
$vo['salt'] = $salt;
//存储token
set_token($vo, $token);
$msg['token'] = $token;
echo json_encode($msg);
exit;
} else {
$msg['error_code'] = 8002;
$msg['notice'] = '注册失败';
echo json_encode($msg);
exit;
}
}
示例3: set
/**
* 编辑
*/
public function set()
{
$share_info = $this->_getData();
//含有sid则为更新,否则为插入
if (isset($this->in['sid']) && strlen($this->in['sid']) == 8) {
$info_new = $this->sql->get($this->in['sid']);
//只更新指定key
foreach ($share_info as $key => $val) {
$info_new[$key] = $val;
}
if ($this->sql->update($this->in['sid'], $info_new)) {
show_json($info_new, true);
}
show_json($this->L['error'], false);
} else {
//插入
$share_list = $this->sql->get();
$new_id = rand_string(8);
while (isset($share_list[$new_id])) {
$new_id = rand_string(8);
}
$share_info['sid'] = $new_id;
if ($this->sql->add($new_id, $share_info)) {
show_json($share_info, true);
}
show_json($this->L['error'], false);
}
show_json($this->L['error'], false);
}
示例4: service_user_autologin
/**
* ユーザのオートログイン
*
* @param string $session_id
*
* @return array
*/
function service_user_autologin($session_id)
{
// セッションを取得
$users = select_sessions(array('select' => 'user_id, keep', 'where' => array('id = :id AND expire > :expire', array('id' => $session_id, 'expire' => localdate('Y-m-d H:i:s')))));
$session = false;
$user_id = null;
if (!empty($users)) {
// セッションを更新
$new_session_id = rand_string();
$resource = update_sessions(array('set' => array('id' => $new_session_id, 'agent' => $_SERVER['HTTP_USER_AGENT'], 'expire' => localdate('Y-m-d H:i:s', time() + $GLOBALS['config']['cookie_expire'])), 'where' => array('id = :id', array('id' => $session_id))));
if ($resource) {
cookie_set('auth[session]', $new_session_id, time() + $GLOBALS['config']['cookie_expire']);
} else {
error('データを編集できません。');
}
if ($users[0]['keep']) {
// ユーザを更新
$resource = update_users(array('set' => array('loggedin' => localdate('Y-m-d H:i:s')), 'where' => array('id = :id', array('id' => $users[0]['user_id']))));
if (!$resource) {
error('データを編集できません。');
}
$session = true;
$user_id = $users[0]['user_id'];
}
}
return array($session, $user_id);
}
示例5: crypt512
function crypt512($pw)
{
if (CRYPT_SHA512 != 1) {
throw new Exception('Hashing mechanism not supported.');
}
return crypt($pw, '$6$' . rand_string(16) . '$');
}
示例6: form_output
/**
* Output form input
*
* @param array
* @param array
* @return string
*/
public function form_output($data, $entry_id, $field)
{
// Get slug stream
$stream = $this->CI->streams_m->get_stream($data['custom']['choose_stream']);
if (!$stream) {
return '<em>' . $this->CI->lang->line('streams:relationship.doesnt_exist') . '</em>';
}
$title_column = $stream->title_column;
// Default to ID for title column
if (!trim($title_column) or !$this->CI->db->field_exists($title_column, $stream->stream_prefix . $stream->stream_slug)) {
$title_column = 'id';
}
// Get the entries
$obj = $this->CI->db->get($stream->stream_prefix . $stream->stream_slug);
$choices = array();
// If this is not required, then
// let's allow a null option
if ($field->is_required == 'no') {
$choices[null] = $this->CI->config->item('dropdown_choose_null');
}
foreach ($obj->result() as $row) {
// Need to replace with title column
$choices[$row->id] = $row->{$title_column};
}
// Output the form input
return form_dropdown($data['form_slug'], $choices, $data['value'], 'id="' . rand_string(10) . '"');
}
示例7: set
/**
* edit
*/
public function set()
{
if ($_SERVER['HTTP_REFERER'] != $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]) {
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
$share_info = $this->_getData();
//Containing sid was updated, otherwise insert
if (isset($this->in['sid']) && strlen($this->in['sid']) == 8) {
$info_new = $this->sql->get($this->in['sid']);
//Only Updates the specified key
foreach ($share_info as $key => $val) {
$info_new[$key] = $val;
}
if ($this->sql->update($this->in['sid'], $info_new)) {
show_json($info_new, true);
}
show_json($this->L['error'], false);
} else {
//insert
$share_list = $this->sql->get();
$new_id = rand_string(8);
while (isset($share_list[$new_id])) {
$new_id = rand_string(8);
}
$share_info['sid'] = $new_id;
if ($this->sql->add($new_id, $share_info)) {
show_json($share_info, true);
}
show_json($this->L['error'], false);
}
show_json($this->L['error'], false);
}
} else {
header('Location: 403.php');
}
}
示例8: finish_auth
function finish_auth($username, $auth_key, $url)
{
// not a good design
if (mb_strlen($auth_key, 'utf-8') != 32) {
return json_encode(array('errorno' => 1));
}
$result = get_user_information($username);
if ($result == null) {
return json_encode(array('errorno' => 2));
}
if (process_auth_key($result['auth_key'], $result['last_time'], $url) != $auth_key) {
return json_encode(array('errorno' => 3));
}
// not good design +1
$new_auth_key = rand_string();
$sql = "UPDATE `account` SET `auth_key`= ? WHERE username= ? LIMIT 1";
$params = array($new_auth_key, $username);
$count = (new MysqlDAO())->execute($sql, $params, 'ss');
$username = $result['username'];
$email = $result['email'];
$verified = $result['verified'];
$reg_time = $result['reg_time'];
$res = array('errorno' => 0, 'user' => array('username' => $username, 'email' => $email, 'verified' => $verified, 'reg_time' => $reg_time));
return json_encode($res);
}
示例9: dopayment
public function dopayment()
{
if ($this->isPost()) {
C('TOKEN_ON', false);
import('@.Com.payment.PaymentFactory');
//订单号
$out_trade_no = date('Ymdhis') . rand_string(4, 1);
$subject = $this->_CFG['site_name'] . '会员充值';
$body = '';
$total_fee = floatval($_REQUEST['amount']);
$show_url = 'http://' . $_SERVER['HTTP_HOST'] . __ROOT__;
if ($this->_CFG['alipay_type'] == 'direct') {
$pay_type = 'alipay';
$status = 103;
} else {
if ($this->_CFG['alipay_type'] == 'warrant') {
$pay_type = 'AlipayWarrant';
$status = 103;
}
}
$params = array('out_trade_no' => $out_trade_no, 'subject' => $subject, 'body' => $body, 'total_fee' => $total_fee, 'show_url' => $show_url);
$data = array('user_id' => $this->_user['user_id'], 'nick' => $this->_user['nick'], 'out_trade_no' => $out_trade_no, 'amount' => $total_fee, 'content' => '在线充值', 'addtime' => LocalTime::getInstance()->gmtime(), 'status' => $status);
M('payment')->add($data);
$payment = PaymentFactory::getPayment($pay_type);
$html_text = $payment->buildForm($params);
$this->assign('form_html', $html_text);
$this->assign('page_title', '在线充值 - ');
$this->display();
}
}
示例10: __construct
public function __construct()
{
/* 当没有uid即 用户没有登陆的时候 自动注册一个用户///
* 当用户退出/或者在注册页面的时候不是继承Common、即UserAction是直接继承Action的
* 用户可以在Login或者Register注册自己的账号 或者 直接修改随机个人帐号
* 随即账号密码为123456
*/
R("Public/session_start_by_user");
session_start();
if (session("uid") == "" || session("uid") == null || session("name") == "" || session("name") == null) {
load("extend");
//引入扩展函数库
do {
//当用外部浏览器登陆的时候就用这个 微信暂时也用这个
$userName = "dc" . rand_string(8, 1);
$userPassword = sha1(md5("123456"));
$flag = D("User")->getUserRegister($userName, $userPassword);
} while (!$flag);
session_set_cookie_params(3600 * 24 * 365, "/");
session('[regenerate]');
session("uid", $flag['uid']);
session("name", $userName);
session("password", $userPassword);
}
//如果没有选择地点则跳转选择地点
if (!session("areaId")) {
$this->redirect("/area");
}
}
示例11: _before_add
public function _before_add()
{
if (!IS_POST) {
$appid = date('Y') . microtime(true) * 10000;
$this->assign('appid', $appid);
$appkey = rand_string(32, -1);
$this->assign('appkey', $appkey);
}
}
示例12: __construct
public function __construct() {
if(C('KUAIDI_KEY')) $this->key = C('KUAIDI_KEY');
$this->par = array(
'type' => '',
'postid' => '',
'id' => 1,
'valicode' => '',
'temp' => rand_string(10),
);
}
示例13: execute
function execute()
{
$result = array();
if (!isset($_POST['email'])) {
$result['retCode'] = '10';
$result['retMsg'] = 'Invalid param.';
$result['result'] = FALSE;
} else {
$date = date('Y-m-d');
$email = $this->input->post('email');
$guser = rand_string(6);
$gp = rand_string(6);
$gpass_decod = $gp;
$gpass = $this->ci->passwordhash->HashPassword($gp);
$name = $this->input->post('name');
$code = sha1(md5(rand_string(6)));
$links = "http://bdsinu.no-ip.biz:8888/kaspoint/index.php/auth/active/verify/" . base64_encode($email);
// change your url
$pesan = "Calon Pelanggan yang Terhormat,\n\n\t\t\t\t\t\tTerima kasih " . $name . " telah melakukan Pendaftaran pada aplikasi Kaspoint PT.Links.co.id\n\t\t\t\t\t\tSilahkan lakukan aktifasi dengan Mengklik \n\t\t\t\t\t\t" . $links . "\n\t\t\t\t\t\tUsername : " . $guser . "\n\t\t\t\t\t\tPassword : " . $gpass_decod . "\n\t\t\t\t\t\t-----------------------";
if (isset($_POST['email'])) {
$email = mysql_real_escape_string($_POST['email']);
$check_for_email = $this->db->query("select * from t_user where email1 ='" . $_POST['email'] . "'");
if ($check_for_email->num_rows()) {
$result['retCode'] = '20';
$result['retMsg'] = 'Email Not Available';
$result['result'] = true;
} else {
$data_user = array('ID_' => $code, 'active' => 0, 'nick_name' => $name, 'email1' => $email, 'username' => $guser, 'password' => $gpass, 'reg_date' => $date, 'nick_name' => $name, 'active_login' => 0, 'role' => "cab483821c4eacfc41fee8c0ffe72216");
$save = $this->mgeneral->save($data_user, 't_user');
/* if(!$save){
$result['retCode'] = '001';
$result['retMsg'] = 'Pendaftaran tidak sukses';
}else{ */
$this->email->from('inu@links.co.id', 'Sales - Kaspoint');
$this->email->to($this->input->post('email'));
$this->email->subject('Dealer Register');
$this->email->message($pesan);
$this->email->send();
$result['username'] = $guser;
$result['password'] = $gpass_decod;
$result['retCode'] = '00';
//$result['url'] = 'localhost/ppob/index.php/auth/login'; //change your url
$result['retMsg'] = 'Success To Registrasi but not active your account.';
$result['result'] = TRUE;
$result['uri'] = $links;
//}
}
} else {
$result['retCode'] = '01';
$result['retMsg'] = 'Error Registration.';
$result['result'] = TRUE;
}
}
$this->output->set_content_type('application/json')->set_output(json_encode($result));
}
示例14: registerFormSubmitted
function registerFormSubmitted()
{
require 'include/configGlobals.php';
connectDatabase();
slashAllInputs();
//This makes sure they did not leave any fields blank
if (!$_POST['username'] | !$_POST['email'] | !$_POST['firstName'] | !$_POST['lastName']) {
die('You did not complete all of the required fields');
}
if (!isUsernameValid($_POST['username'])) {
die('Sorry, that username is invalid. Please go back and try again.');
}
// checks if the username is in use
$usercheck = $_POST['username'];
$check = mysql_query("SELECT username FROM users WHERE username = '{$usercheck}'") or die(mysql_error());
$check2 = mysql_num_rows($check);
//if the name exists it gives an error
if ($check2 != 0) {
die('Sorry, the username ' . $_POST['username'] . ' is already in use. Please go back and try again.');
}
$emailcheck = $_POST['email'];
$check = mysql_query("SELECT email FROM users WHERE email = '{$emailcheck}'") or die(mysql_error());
$check2 = mysql_num_rows($check);
//if the email exists it gives an error
if ($check2 != 0) {
die('Sorry, the email ' . $_POST['email'] . ' has already been registered. Please go back and try again.');
}
$tempPassword = rand_string(16);
// here we encrypt the password and add slashes if needed
$hashPassword = md5($tempPassword);
$hashUsername = md5($_POST['username']);
$hash256Password = bin2hex(mhash(MHASH_SHA256, $tempPassword));
$hash256Username = bin2hex(mhash(MHASH_SHA256, $_POST['username']));
$creationDate = date('Y-m-d');
// now we insert it into the database
$insert = "INSERT INTO users (username, pass, sha256_user, sha256_pass, fname, lname, addr1, addr2, city, state, zip, hphone, cphone, email, econtact, econtact_phone, econtact_rel, creation) VALUES (\n '" . $_POST['username'] . "',\n '" . $hashPassword . "',\n\t\t '" . $hash256Username . "',\n\t\t '" . $hash256Password . "',\n '" . $_POST['firstName'] . "',\n '" . $_POST['lastName'] . "',\n '" . $_POST['address1'] . "',\n '" . $_POST['address2'] . "',\n '" . $_POST['city'] . "',\n '" . $_POST['state'] . "',\n '" . $_POST['zipCode'] . "',\n '" . $_POST['homePhone'] . "',\n '" . $_POST['cellPhone'] . "',\n '" . $_POST['email'] . "',\n '" . $_POST['econtact'] . "',\n '" . $_POST['econtactPhone'] . "',\n '" . $_POST['econtactRel'] . "',\n '" . $creationDate . "'\n )";
$add_member = mysql_query($insert);
$to = $_POST['email'];
$from = $email_Administrator;
$subject = 'Registered on ' . $club_Abbr . ' Online Registration Site';
$message = "--{$mime_boundary}\n";
$message .= "Content-Type: text/plain; charset=UTF-8\r\n";
$message .= "Content-Transfer-Encoding: 8bit\r\n";
$message .= 'Thank you for registering on the ' . $club_Abbr . ' Online Registration site.' . "\n" . "\n" . 'Your username is: [ ' . $usercheck . " ]\n" . 'Your temporary password is: [ ' . $tempPassword . " ]\n" . "\n" . 'Login at ' . $http_Logout . ' to change your password and register for events.' . "\n" . "\n" . 'Thank you!' . "\n" . '- ' . $club_Abbr . ' Administration' . "\n";
$message .= "--{$mime_boundary}--\n\n";
if (sendEmail($to, $from, $subject, $message) != false) {
echo "<h1>Registered</h1>\n";
echo "Thank you, you have registered. An email has been sent to " . $to . " \n";
echo "with your username and temporary password. Depending on internal server traffic, this may take some time.<br><br>\n";
echo "When you receive your temporary password you may <a href=\"index.php\">login</a> to continue.\n";
} else {
echo "<h1>Internal Email Error. Please contact administrator at " . $email_Administrator . "</h1>\n";
}
}
示例15: changePassword
public function changePassword($intEditorID, $strOldPassword, $strNewPassword)
{
if ($strOldPassword == $strNewPassword) {
return new returnData(0, NULL);
}
$query = "UPDATE editors \n SET password = MD5('{$strNewPassword}'), read_write_token = '" . rand_string(64) . "'\n WHERE password = MD5('{$strOldPassword}')\n AND editor_id = {$intEditorID}";
Module::query($query);
if (mysql_affected_rows() < 1) {
return new returnData(4, NULL, 'No editors exist with matching ID and password');
}
return new returnData(0, NULL);
}