uniqid() public static method

Generate a unique ID.
public static uniqid ( ) : string
return string Returns the unique identifier, as a string.
Example #1
0
 public function perform()
 {
     $hash = Request::getString($_REQUEST['x']);
     if (!strlen($hash) || base64_decode($hash, true) === false) {
         $this->req->setResult(['success' => false, 'error' => 'Wrong format of extTokenHash']);
         return;
     }
     $this->appInstance->externalAuthTokens->findByExtTokenHash($hash, function ($result) use($hash) {
         if ($result) {
             $this->req->setResult(['success' => false, 'error' => 'This token was already used.']);
             return;
         }
         $ip = $this->req->getIp();
         $intToken = Crypt::hash(Daemon::uniqid() . "" . $ip . "" . Crypt::randomString());
         $this->appInstance->externalAuthTokens->save(['extTokenHash' => $hash, 'intToken' => $intToken, 'ip' => $ip, 'useragent' => Request::getString($_SERVER['HTTP_USER_AGENT']), 'ctime' => microtime(true), 'status' => 'new'], function ($lastError) use($intToken) {
             if (!isset($lastError['n']) || $lastError['n'] === 0) {
                 $this->req->setResult(['success' => false, 'errors' => ['code' => 'Sorry, internal error.']]);
                 return;
             }
             $type = Request::getString($_REQUEST['type']);
             if ($type === 'email') {
                 // send email....
             } elseif ($type === 'redirect') {
                 $this->req->redirectTo(HTTPClient::buildUrl(['/' . $this->req->locale . '/account/extauth', 'i' => $intToken]), false);
             }
             $this->req->setResult(['success' => true, 'intToken' => $intToken]);
         });
     });
 }
Example #2
0
 public function setPassword($value)
 {
     if (($r = static::checkPasswordFormat($value)) !== true) {
         throw new \Exception($r);
     }
     $this->setProperty('salt', $salt = $this->appInstance->config->cryptsalt->value . Crypt::hash(Daemon::uniqid() . "" . $this['email']));
     $this->setProperty('password', Crypt::hash($value, $salt . $this->appInstance->config->cryptsaltextra->value));
     return $this;
 }
Example #3
0
 protected function getAuthorizationHeader($url, $oauth_params = [])
 {
     $params = ['oauth_consumer_key' => $this->cmp->config->twitter_app_key->value, 'oauth_nonce' => Daemon::uniqid(), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_timestamp' => time(), 'oauth_version' => '1.0'];
     if (!empty($oauth_params)) {
         $params = array_merge($params, $oauth_params);
     }
     $params['oauth_signature'] = OAuth::getSignature('POST', $url, $params, $this->cmp->config->twitter_app_secret->value);
     $header_params = [];
     foreach ($params as $param => $value) {
         $header_params[] = rawurlencode($param) . '="' . rawurlencode($value) . '"';
     }
     $header = 'OAuth ' . implode(', ', $header_params);
     return $header;
 }
Example #4
0
 /**
  * Save
  * @param string $str JSON string
  */
 public function __construct($str)
 {
     $this->id = Daemon::uniqid();
     static::$tr['"' . $this->id . '"'] = $str;
 }
Example #5
0
 /**
  * @param $req
  * @return array
  */
 public function getAccountBase($req)
 {
     return ['email' => '', 'location' => '', 'ukey' => Crypt::randomString(16), 'confirmationcode' => substr(md5($req->attrs->server['REMOTE_ADDR'] . "" . Daemon::uniqid() . "" . $this->appInstance->config->cryptsalt->value . "" . microtime(true) . "" . mt_rand(0, mt_getrandmax())), 0, 6), 'regdate' => time(), 'etime' => time(), 'ttlSession' => 1200, 'ip' => $req->attrs->server['REMOTE_ADDR'], 'subscription' => 'daily', 'aclgroups' => array('Users'), 'acl' => array()];
 }
Example #6
0
 /**
  * Sends arbitrary command
  * @param string   $packet    A packet for sending by the connected client to Asterisk
  * @param callable $cb        Callback called when response received
  * @param array    $assertion If more events may follow as response this is a main part or full an action complete event indicating that all data has been sent
  */
 protected function command($packet, $cb, $assertion = null)
 {
     if ($this->finished) {
         throw new ConnectionFinished();
     }
     if ($this->state !== self::CONN_STATE_HANDSHAKED_OK) {
         return;
     }
     $actionId = Daemon::uniqid();
     if (!is_callable($cb, true)) {
         $cb = false;
     }
     $this->callbacks[$actionId] = CallbackWrapper::wrap($cb);
     if ($assertion !== null) {
         $this->assertions[$actionId] = $assertion;
     }
     $this->write($packet);
     $this->write('ActionID: ' . $actionId . "\r\n\r\n");
 }