function RandomToken($Length = 64) { return substr(hash("sha512", jf::rand()), 0, $Length); }
/** * Creates a hashed password * @param string $Username * @param string $RawPassword * @param string $DynamicSalt * @param integer $Protocol */ public function Make($Username, $RawPassword, $DynamicSalt = null, $Protocol = null) { if ($DynamicSalt === null) { $this->DynamicSalt = hash("sha512", jf::rand()); } else { $this->DynamicSalt = $DynamicSalt; } if ($Protocol === null) { $Protocol = $this->Protocol(); } $this->Username = $Username; if ($Protocol == 1) { $this->Password = hash("sha512", strtolower($this->Username()) . $RawPassword . $this->Salt() . $this->StaticSalt()); } }
/** * Outputs the image to the browser and terminates */ private function DumpImage() { // $text=$this->Generate(); $text = $this->UnicodeTextForImage($this->Generate()); // $font=dirname(__FILE__)."/captcha/font.ttf"; $font = __DIR__ . "/font.ttf"; $fontSize = 28; $width = ($fontSize - 5) * strlen($text) + 40; $height = $fontSize + 30; $img = imagecreatetruecolor($width, $height); imagealphablending($img, true); imagesavealpha($img, true); $r = mt_rand(80, 235); $b = mt_rand(80, 235); $g = mt_rand(80, 235); $bgcolor = imagecolorallocatealpha($img, $r, $g, $b, 0); imagefill($img, 1, 1, $bgcolor); $ex = -mt_rand(80, min($r, $b, $g)); // if (mt_rand(0,1)) $ex=-$ex; $b += $ex; $r += $ex; $g += $ex; $color = imagecolorallocate($img, $r, $b, $g); $text = explode(" ", $text); $sumWidth = 0; $b += 50; $g += 50; $r += 50; $elcolor = imagecolorallocatealpha($img, $r, $g, $b, 20); //ellipses for ($i = 0; $i < 3; ++$i) { $ellipseWidth = mt_rand(30, $width - 50); $ellipsePosX = mt_rand(min($ellipseWidth, $width - $ellipseWidth), max($ellipseWidth, $width - $ellipseWidth)); $ellipseHeight = mt_rand(10, 40); $ellipsePosY = mt_rand(min($ellipseHeight, $height - $ellipseHeight), max($ellipseHeight, $height - $ellipseHeight)); imageellipse($img, $ellipsePosX, $ellipsePosY, $ellipseWidth, $ellipseHeight, $elcolor); imagefill($img, $ellipsePosX, $ellipsePosY, $elcolor); } //dots for ($i = 0; $i < $width * $height / 12; ++$i) { $x = jf::rand(0, $width); $y = jf::rand(0, $height); imagesetpixel($img, $x, $y, $color); } //dots for ($i = 0; $i < $width / 10; ++$i) { $x1 = jf::rand(0, $width); $x2 = jf::rand(0, $width); $y1 = jf::rand(0, $width); $y2 = jf::rand(0, $width); imageline($img, $x1, $y1, $x2, $y2, $color); } //arcs for ($i = 0; $i < $width / 4; ++$i) { $cx = jf::rand(0, $width); $cy = jf::rand(0, $height); $start = jf::rand(0, 180); $end = jf::rand(0, 180); $awidth = jf::rand(0, max(min($cx, $width - $cx), 10)); $aheight = jf::rand(0, max(min($cy, $height - $cy), 10)); imagearc($img, $cx, $cy, $awidth, $aheight, $start, $end, $color); } //text for ($i = 0; $i < count($text); ++$i) { imagettftext($img, $fontSize, mt_rand(-5, 5), 10 + ($fontSize - 8) * $sumWidth + 20 * $i, $fontSize + mt_rand(-10, 10) + 10, $color, $font, $text[$i]); $sumWidth += strlen($text[$i]); } if (imageistruecolor($img)) { header("content-type: image/png"); echo imagepng($img); } exit; }