note 46901 added to ref.image

From: Date: Wed, 27 Oct 2004 14:17:04 +0000
Subject: note 46901 added to ref.image
Groups: php.notes 
Request: Send a blank email to php-notes+get-79182@lists.php.net to get a copy of this message
// create random image and chack if user insert the sam password <?php function get_rnd_iv($iv_len) { $iv = ''; while ($iv_len-- > 0) { $iv .= chr(mt_rand() & 0xff); } return $iv; } function md5_encrypt($plain_text, $password, $iv_len = 16) { $plain_text .= "\x13"; $n = strlen($plain_text); if ($n % 16) $plain_text .= str_repeat("\0", 16 - ($n % 16)); $i = 0; $enc_text = get_rnd_iv($iv_len); $iv = substr($password ^ $enc_text, 0, 512); while ($i < $n) { $block = substr($plain_text, $i, 16) ^ pack('H*', md5($iv)); $enc_text .= $block; $iv = substr($block . $iv, 0, 512) ^ $password; $i += 16; } return base64_encode($enc_text); } function md5_decrypt($enc_text, $password, $iv_len = 16) { $enc_text = base64_decode($enc_text); $n = strlen($enc_text); $i = $iv_len; $plain_text = ''; $iv = substr($password ^ substr($enc_text, 0, $iv_len), 0, 512); while ($i < $n) { $block = substr($enc_text, $i, 16); $plain_text .= $block ^ pack('H*', md5($iv)); $iv = substr($block . $iv, 0, 512) ^ $password; $i += 16; } return preg_replace('/\\x13\\x00*$/', '', $plain_text); } function genpass($size = 6) { $possible = "0123456789QWERTYUIOPLKJHGFDSAZXCVBNM"; $string = ""; while ($i < $size) { // pick a random character from the possible ones $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); // we don't want this character if it's already in the password if (!strstr($password, $char)) { $password .= $char; $i++; } } return $password; } function imgsecuregen($password) { $width = 11*6; $height = 30; $im = ImageCreate($width, $height); $bg = imagecolorallocate($im, 200, 42, 255); $black = imagecolorallocate($im, 0, 0, 0); $grey = imagecolorallocate($im, 90, 170, 220); imagerectangle($im,0, 0, $width-1, $height-1, $grey); imagestring($im, 5, $size, 5, $password, $black); imagejpeg($im,"xx.jpg"); imagedestroy($im); } $key="HELLO WORLD"; if ((!$_POST["pasw"])||(!$_POST["valr"])) { $password = genpass(); imgsecuregen($password); echo session_id(); $enc_text = md5_encrypt($password, $key); echo "<img src='xx.jpg'> <br> <FORM method='POST' target='_self'> <INPUT TYPE='HIDDEN' name='pasw' value='$enc_text'> <INPUT TYPE='TEXT' name='valr'> <INPUT TYPE='SUBMIT' name='submit'> </FORM> "; // $random = imgsecuregen(5); action='secur' } else { $systemcode = $_POST["pasw"] ; $userinsertcode = strtolower($_POST["valr"]) ; $systemcode = strtolower(md5_decrypt($systemcode, $key)); $userinsertcode = str_replace("o","0",$userinsertcode); $systemcode = str_replace("o","0",$systemcode); if ($systemcode == $userinsertcode) print ($systemcode); else print ("Error in image code "); } ?> ---- Manual Page -- http://www.php.net/manual/en/ref.image.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46901 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46901&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46901&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46901&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46901&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46901&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46901&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+46901&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#79182) next »