hash() public static méthode

Generate keccak hash for string with salt
Deprecation:
public static hash ( string $str, string $salt = '', boolean $plain = false ) : string
$str string Data
$salt string Salt
$plain boolean Is plain text?
Résultat string
Exemple #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]);
         });
     });
 }
Exemple #2
0
 public function perform()
 {
     $str = Request::getString($_REQUEST['str']);
     $size = Request::getInteger($_REQUEST['size']);
     $rounds = Request::getInteger($_REQUEST['rounds']);
     if (!$rounds) {
         $rounds = 24;
     }
     $salt = '$512=24';
     $hash = Crypt::hash($str, $salt);
     $hex = trim(str_replace('\\x', ' ', Debug::exportBytes(base64_decode($hash), true)));
     $this->req->setResult(['stringWithSalt' => $str . $salt, 'base64' => $hash, 'salt' => $salt, 'hex' => $hex, 'rounds' => 24]);
 }
Exemple #3
0
 /**
  * @param string $password
  * @return bool
  */
 public function checkPassword($password)
 {
     return !isset($this->obj['password']) ? false : Crypt::compareStrings($this->obj['password'], Crypt::hash($password, $this->obj['salt'] . $this->appInstance->config->cryptsaltextra->value));
 }