当前位置: 首页>>代码示例>>PHP>>正文


PHP generateToken函数代码示例

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


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

示例1: getUploadToken

 function getUploadToken()
 {
     requireRequestMethod("POST");
     /* FIXME: token should expire, based on server request? */
     /* FIXME: what if upload size is not known in time? transcode web service for example... */
     $absPath = $this->validatePath(getRequest('relativePath', TRUE), FTS_PARENT);
     /* make sure the uploaded file name is unique */
     $absPath = $this->getUniqueName($absPath);
     /* verify fileSize
      *
      * NOTE: fileSize *is* required, but 0 is a valid file size, but also
      * seen as "empty" by PHP, so we work around it like this...
      */
     $fileSize = (int) getRequest('fileSize', FALSE, 0);
     if ($fileSize < 0) {
         throw new Exception("invalid filesize");
     }
     $token = generateToken();
     try {
         $stmt = $this->dbh->prepare("INSERT INTO uploadTokens (token, filePath, fileSize) VALUES (:token, :filePath, :fileSize)");
         $stmt->bindParam(':token', $token);
         $stmt->bindParam(':filePath', $absPath);
         $stmt->bindParam(':fileSize', $fileSize);
         $stmt->execute();
         $uploadLocation = getProtocol() . getServerName() . $_SERVER['PHP_SELF'] . "?action=uploadFile&token={$token}";
         return array("uploadLocation" => $uploadLocation, "absPath" => $absPath);
     } catch (Exception $e) {
         throw new Exception("database query failed");
     }
 }
开发者ID:kaichuang1992,项目名称:filetrader,代码行数:30,代码来源:Files.class.php

示例2: DoQuery

function DoQuery($n, $c, $p1, $p2, $p3, $p4, $p5) {
	$str = "{\"result\":1}";
	date_default_timezone_set("Asia/Hong_Kong");
	$t_str = date("YmdHis");
	$commit_date = date("Y-m-d H:i:s");
	$pname = generateToken().".${t_str}.";
	$path1 = "./files/${pname}1";
	$path2 = "./files/${pname}2";
	$path3 = "./files/${pname}3";
	$path4 = "./files/${pname}4";
	$path5 = "./files/${pname}5";
	$dbp1 = "";
	$dbp2 = "";
	$dbp3 = "";
	$dbp4 = "";
	$dbp5 = "";
	if (isset($p1)) { move_uploaded_file($p1["tmp_name"], $path1); $dbp1 = "${pname}1"; }
	if (isset($p2)) { move_uploaded_file($p2["tmp_name"], $path2); $dbp2 = "${pname}2"; }
	if (isset($p3)) { move_uploaded_file($p3["tmp_name"], $path3); $dbp3 = "${pname}3"; }
	if (isset($p4)) { move_uploaded_file($p4["tmp_name"], $path4); $dbp4 = "${pname}4"; }
	if (isset($p5)) { move_uploaded_file($p5["tmp_name"], $path5); $dbp5 = "${pname}5"; }
	$db = openConnection();
	$stmt = $db->prepare("insert into feedback(nickname, comment, photo1, photo2, photo3, photo4, photo5, commit_date) values (?, ?, ?, ?, ?, ?, ?, ?)");
	$stmt->bind_param("ssssssss", $n, $c, $dbp1, $dbp2, $dbp3, $dbp4, $dbp5, $commit_date);
	$stmt->execute();
	$rows = intval($stmt->affected_rows);
	$stmt->close();
	closeConnection($db);
	if ($rows != 0) {
		$str = "{\"result\":0}";
	}
	return $str;	
}
开发者ID:rarnu,项目名称:root-tools,代码行数:33,代码来源:feedback.php

示例3: checkToken

function checkToken()
{
    /*****************************************************************************************
     * Check the posted token for correctness
     ******************************************************************************************/
    $oldToken = "";
    $testToken = "";
    $tokenStr = "";
    $page = basename($_SERVER['PHP_SELF']);
    $oldToken = $_POST["token"];
    $tokenStr = "IP:" . $_SESSION["ip"] . ",SESSIONID:" . session_id() . ",GUID:" . $_SESSION["guid"];
    $testToken = sha1($tokenStr . $_SESSION["salt"] . $_SESSION["salt"]);
    $checkToken = False;
    if ($oldToken === $testToken) {
        $diff = time() - $_SESSION["time"];
        if ($diff <= 300) {
            // Five minutes max
            if ($_SESSION["usecookie"]) {
                if ($_COOKIE["token"] === $oldToken) {
                    /*****************************************************************************************
                     * Destroy the old form token, then
                     * generate a new token for the form, which may or may not be needed. We want to do this
                     * before headers are written. When writeToken() or writeTokenH() is called we are only 
                     * writing the pre-generated token to the form. The cookie will have already been written.
                     ******************************************************************************************/
                    setcookie("token", '', time() - 42000);
                    generateToken();
                    return true;
                } else {
                    $_SESSION = array();
                    if (isset($_COOKIE[session_name()])) {
                        setcookie(session_name(), '', time() - 42000);
                    }
                    session_destroy();
                    header("Location: http://" . lg_domain . lg_form_error . "?p=" . $page . "&t=ec");
                }
            } else {
                return True;
            }
        } else {
            $_SESSION = array();
            if (isset($_COOKIE[session_name()])) {
                setcookie(session_name(), '', time() - 42000);
            }
            session_destroy();
            header("Location: http://" . lg_domain . lg_form_error . "?p=" . $page . "&t=et");
        }
    } else {
        $_SESSION = array();
        if (isset($_COOKIE[session_name()])) {
            setcookie(session_name(), '', time() - 42000);
        }
        session_destroy();
        header("Location: http://" . lg_domain . lg_form_error . "?p=" . $page . "&t=e");
    }
}
开发者ID:jeffreyhi1,项目名称:loginsystem-rd,代码行数:56,代码来源:form_token.php

示例4: generateToken

/**
 * A function that generates a hash that is not already 
 * in use. Adds letters to username and password until 
 * something unique is created.
 */
function generateToken($pdo, $username, $password)
{
    $hash = hash('ripemd160', $username . $password);
    $sql = "SELECT COUNT(*) FROM calendars WHERE token = :hash";
    $result = $pdo->prepare($sql);
    $result->execute(array('hash' => $hash));
    if ($result->fetchColumn() > 0) {
        return generateToken($pdo, $username . 'a', $password . 'b');
    }
    return $hash;
}
开发者ID:jonasdahl,项目名称:fogis-calendar-export,代码行数:16,代码来源:handleSubmit.php

示例5: run

 public function run()
 {
     parent::run();
     $this->getInputJson();
     $userId = login($this->input['username'], $this->input['password']);
     if (!$userId) {
         throw new \Exception("Invalid username or password.");
     }
     $token = generateToken($userId);
     $this->return['token'] = $token;
 }
开发者ID:kolesar-andras,项目名称:miserend.hu,代码行数:11,代码来源:Login.php

示例6: sendTokenChange

function sendTokenChange($email, $username, $old_email)
{
    require_once MODELES . 'membres/token.php';
    if ($token = generateToken($email, $username, $old_email)) {
        $tokenlink = 'http://' . $_SERVER['HTTP_HOST'] . getLink(['membres', 'confirm', $token]);
    } else {
        return False;
    }
    if (mail($email, 'Confirmer votre nouvelle adresse e-mail', "Bonjour !\n" . "Merci de cliquer sur le lien ci-dessous pour confirmer votre nouvelle adresse e-mail :\n" . $tokenlink . "\n" . "Si le lien ne fonctionne pas, copiez-collez l'adresse dans votre navigateur.\n\n" . "Merci et à bientôt !\n" . "-- L'équipe EventEase", 'From: no-reply@eventease.com')) {
        return True;
    } else {
        return False;
    }
}
开发者ID:aurelienshz,项目名称:g1a,代码行数:14,代码来源:sendToken.php

示例7: firstUse

 public function firstUse($stunum)
 {
     $url = 'http://hongyan.cqupt.edu.cn/RedCenter/Api/Handle/index';
     //        $tmpArr = array('cyxbs',"$stunum",'firstUse');
     //        sort($tmpArr, SORT_STRING);
     //        $t = md5( sha1( implode( $tmpArr, '|' ) ) );
     $token = generateToken('cyxbs', $stunum, 'firstUse');
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_HEADER, false);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, "type=firstUse&stu={$stunum}&id=cyxbs&token=" . $token);
     curl_exec($ch);
     //$output = json_decode(curl_exec($ch),TRUE);
 }
开发者ID:RedrockTeam,项目名称:redcenter,代码行数:15,代码来源:PhoneController.class.php

示例8: post_login

 function post_login($data)
 {
     if ($_SESSION["login_id"] != null) {
         $response["success"] = "true";
         $response["code"] = "1";
         $response["message"] = "você esta logado";
         return json_encode($response);
         #throw new Exception("você esta logado");
     } else {
         if (empty($data->username) or empty($data->password)) {
             throw new Exception("Login ou senha precisam ser preenchidos");
         }
         #verifica usario no banco
         $db_user = User::find('all', array('conditions' => array('username = ? AND password = ? ', $data->username, hashpassword($data->password))));
         #->to_json() $data->id
         #fim
         if ($db_user != null) {
             //array push result
             $result = array();
             foreach ($db_user as $data) {
                 //update ip e login
                 $sql = User::find($data->id);
                 $sql->update_attributes(array('last_ip' => $_SERVER['REMOTE_ADDR'], 'last_login' => date("Y-m-d  H:i:s")));
                 $sql->save();
                 array_push($result, $data->to_array());
                 //using to_array instead of to_json
             }
             $token = generateToken($db_user);
             #fazer o login so add apikey e session
             $this->doLogin($db_user);
             unset($result->password);
             unset($result->password_salt);
             unset($result->last_ip);
             $response["success"] = "true";
             $response["code"] = "1";
             $response["message"] = "Sucesso - Bem vindo ";
             //para enviar dados atuais
             $newresult = $this->getPerfile();
             $response["result"] = $newresult;
             return json_encode($response);
         } else {
             throw new Exception("Erro ao efetuar login. Usuário/Senha incorretos");
         }
         return false;
     }
 }
开发者ID:joeymetal,项目名称:restful-sdti,代码行数:46,代码来源:AuthenticateController.php

示例9: register

function register($conn)
{
    $username = $_POST['username'];
    $password = sha1($_POST['password']);
    $email = $_POST['email'];
    $token = generateToken();
    $sql = 'INSERT INTO users (username, password, email, token) VALUES (?, ?, ?, ?)';
    $stmt = $conn->prepare($sql);
    try {
        if ($stmt->execute(array($username, $password, $email, $token))) {
            setcookie('token', $token, 0, "/");
            echo 'Account Registered';
        }
    } catch (PDOException $e) {
        echo $e->getMessage();
        //echo 'Username or Email Already Registered';
    }
}
开发者ID:gonzalez-jose-wm,项目名称:Shopping-Cart-Project,代码行数:18,代码来源:trial.php

示例10: register

function register($conn)
{
    $password = sha1($_POST['password']);
    $email = $_POST['email'];
    $token = generateToken();
    $sql = 'INSERT INTO users (password, email, token) VALUES (?, ?, ?)';
    $stmt = $conn->prepare($sql);
    try {
        if ($stmt->execute(array($password, $email, $token))) {
            setcookie('token', $token, 0, "/");
            $sql = 'INSERT INTO orders (users_id, status) (SELECT u.id, "new" FROM users u WHERE u.token = ?)';
            $stmt1 = $conn->prepare($sql);
            if ($stmt1->execute(array($token))) {
                echo 'Account Registered';
            }
        }
    } catch (PDOException $e) {
        echo $e->getMessage();
    }
}
开发者ID:chu-christopher-wm,项目名称:Shopping-Cart-Project,代码行数:20,代码来源:index.php

示例11: create

 public function create($options = array())
 {
     if (!isValid($options['email'], 'email')) {
         return formatErrors(604);
     }
     if (!isValid($options['password'], 'password')) {
         return formatErrors(602);
     }
     // Make sure email does not exist already
     $total = $this->count("email = '" . $options['email'] . "'");
     if ($total > 0) {
         return formatErrors(603);
     }
     // If you made it this far, we need to add the record to the DB
     $options['password'] = generateHash($options['password']);
     $options['created_on'] = date("Y-m-d H:i:s");
     // Create user token
     do {
         $options['user_token'] = generateToken(30) . md5(time());
         $total = $this->count("user_token = '" . $options['user_token'] . "'");
         // If by some freak chance there is a collision
         // Report it
         if ($total > 0) {
             log_message('debug', 'User token collision detected on key of `' . $options['user_token'] . '`');
         }
     } while ($total > 0);
     // Add record
     $q = $this->db->insert_string('users', $options);
     $res = $this->db->query($q);
     // Check for errors
     $this->sendException();
     if ($res === true) {
         $user_id = $this->db->insert_id();
         return $this->read($user_id);
     } else {
         return formatErrors(500);
     }
 }
开发者ID:iweave,项目名称:unmark,代码行数:38,代码来源:users_model.php

示例12: login

function login($conn)
{
    setcookie('token', "", 0, "/");
    $username = $_POST['username'];
    $password = sha1($_POST['password']);
    $sql = 'SELECT * FROM users WHERE username = ? AND password = ?';
    $stmt = $conn->prepare($sql);
    if ($stmt->execute(array($username, $password))) {
        $valid = false;
        while ($row = $stmt->fetch()) {
            $valid = true;
            $token = generateToken();
            $sql = 'UPDATE users SET token = ? WHERE username = ?';
            $stmt1 = $conn->prepare($sql);
            if ($stmt1->execute(array($token, $username))) {
                echo 'Login Successful';
            }
        }
        if (!$valid) {
            echo 'Username or Password Incorrect';
        }
    }
}
开发者ID:shumway-kyle-wm,项目名称:SimpleCart,代码行数:23,代码来源:index.php

示例13: register

function register($conn)
{
    $password = sha1($_POST['password']);
    $email = $_POST['email'];
    $name_first = $_POST['name_first'];
    $name_last = $_POST['name_last'];
    $address = $_POST['address'];
    $realtor = $_POST['realtor'];
    $token = generateToken();
    $sql = 'INSERT INTO users (password, email, name_first, name_last, address, realtor, token) VALUES (?, ?, ?, ?, ?, ?, ?)';
    $stmt = $conn->prepare($sql);
    try {
        if ($stmt->execute(array($password, $email, $name_first, $name_last, $address, $realtor, $token))) {
            setcookie('token', $token, 0, "/");
            $sql = 'INSERT INTO orders (users_id, status) (SELECT u.id, "new" FROM users u WHERE u.token = ?)';
            $stmt1 = $conn->prepare($sql);
            if ($stmt1->execute(array($token))) {
                echo 'Account Registered';
            }
        }
    } catch (PDOException $e) {
        echo 'Email already registered.';
    }
}
开发者ID:Tucker-Cole-wm,项目名称:Shopping-Cart-Project,代码行数:24,代码来源:register.php

示例14: generateHash

function generateHash($str)
{
    $salt = generateToken(50);
    if (CRYPT_SHA512 == 1) {
        return crypt($str, '$6$rounds=5000$' . $salt . '$');
    }
    if (CRYPT_SHA256 == 1) {
        return crypt($str, '$5$rounds=5000$' . $salt . '$');
    }
    if (CRYPT_BLOWFISH == 1) {
        return crypt($str, '$2a$07$' . $salt . '$');
    }
    if (CRYPT_MD5 == 1) {
        return crypt($str, '$1$' . $salt . '$');
    }
    if (CRYPT_EXT_DES == 1) {
        return crypt($str, '_J9' . $salt);
    }
    if (CRYPT_STD_DES == 1) {
        return crypt($str, $salt);
    }
    return false;
    // Throw exception once everything is hooked up
}
开发者ID:iweave,项目名称:unmark,代码行数:24,代码来源:hash_helper.php

示例15: connect

?>



    <!-- Test, Bild -->
    <img class="img-responsive" src="coverphoto.jpg" alt="Coverphoto">


    <!-- Visa produkter -->
    <?php 
$con = connect();
// to prevent undefined index notice
$action = isset($_GET['action']) ? $_GET['action'] : "";
$product_id = isset($_GET['product_id']) ? $_GET['product_id'] : "1";
$productName = isset($_GET['productName']) ? $_GET['productName'] : "";
$token = generateToken();
if ($action == 'added') {
    echo "<div class='alert alert-info'>";
    echo "<strong>{$productName}</strong> tillagt i varukorgen!";
    echo "</div>";
}
if ($action == 'exists') {
    echo "<div class='alert alert-info'>";
    echo "<strong>{$productName}</strong> finns redan i varukorgen!";
    echo "</div>";
}
$query = "SELECT id, productName, price FROM Products ORDER BY productName";
$stmt = $con->prepare($query);
$stmt->execute();
$num = $stmt->rowCount();
if ($num > 0) {
开发者ID:johanmansson,项目名称:EITF05-Webbsakerhet,代码行数:31,代码来源:webbshop.php


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