Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory limit reached while exectuting a PHP script
    primarykey
    data
    text
    <p>I am currently revising my register script to add PDO and bcrypt. However I run into an error I feel when I try to iterate my hash. I had the rounds initially set to 10000 as I seen tutorials with rounds of 60000+ but that was taking ages. So then I set it to 2 just to test it out and then I got an error : </p> <pre><code>[Tue Dec 25 10:45:07 2012] [error] [] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 133431193 bytes) in /var/www/register_script.php on line 28, referer: </code></pre> <p>My entire register script goes as fallows : </p> <pre><code>&lt;?php //Minor work needed need to finish user verification $host="localhost"; // Host name $username="root"; // Mysql username $password="testdbpass"; // Mysql password $db_name="test"; // Database name // Connect to server via PHP Data Object $dbh = new PDO("mysql:host=localhost;dbname=test;", $username, $password); $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); CRYPT_BLOWFISH or die ('No Blowfish found.'); // Creating the salt $Blowfish_Pre = '$2y$15$'; $Blowfish_End = '$'; $Allowed_Chars = '/.ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; $char_len = 63; $salt_length = 60; for($round=0;$round&lt;$salt_length;$roundi++) { $salt .= $Allowed_Chars[mt_rand(0,$char_len)]; } $bcrypt_salt = $Blowfish_Pre . $salt . $Blowfish_End; //Salt creating stops here //Creating the hash and password $password = $_POST['password']; $hashed_password = crypt($password, $bcrypt_salt); for($round=0; $round&lt;2; $round++) { $hashed_password = crypt($password, $bcrypt_salt); } // Insert statements with PDO try { $query = $dbh-&gt;prepare("INSERT INTO `users_blowfish` (username, email, fname, lname, salt, password) VALUES (:username, :email, :first, :last, :salt, :hash)"); $query-&gt;execute( array( 'username' =&gt; $_POST['username'], 'email' =&gt; $_POST['email'], 'first' =&gt; $_POST['fname'], 'last' =&gt; $_POST['lname'], 'salt' =&gt; $bcrypt_salt, 'hash' =&gt; $hashed_password )); } catch (PDOException $e) { error_log($e-&gt;getMessage()); die($e-&gt;getMessage()); } $dbh= null; ?&gt; &lt;html&gt; &lt;body&gt; &lt;p&gt; Thank you for registering your account. Please wait for administrator approval before doing anything else. Thank you - System Administrator. &lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>If I take out the for statement :</p> <pre><code>$hashed_password = crypt($password, $bcrypt_salt); for($round=0; $round&lt;2; $round++) { $hashed_password = crypt($password, $bcrypt_salt); } </code></pre> <p>Then it all work. However what confuses me is that I have two for statements the one above ^</p> <p>and this one : </p> <pre><code>$salt_length = 60; for($round=0;$round&lt;$salt_length;$roundi++) { $salt .= $Allowed_Chars[mt_rand(0,$char_len)]; } </code></pre> <p>I guess my questions summed up are 1) Why does the for statement by the hash make the registration extremely slow and the for statement by the salt creation doesn't affect the speed of registration?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload