Welcome, guest | Sign In | My Account | Store | Cart
<?php

/**
 * This function generates a password salt as a string of x (default = 15) characters
 * in the a-zA-Z0-9!@#$%&*? range.
 * @param $max integer The number of characters in the string
 * @return string
 * @author AfroSoft <info@afrosoft.tk>
 */
function generateSalt($max = 15) {
        $characterList = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&*?";
        $i = 0;
        $salt = "";
        while ($i < $max) {
            $salt .= $characterList{mt_rand(0, (strlen($characterList) - 1))};
            $i++;
        }
        return $salt;
}

?>

Diff to Previous Revision

--- revision 5 2012-04-30 21:42:03
+++ revision 6 2012-07-10 19:52:17
@@ -11,7 +11,7 @@
         $characterList = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&*?";
         $i = 0;
         $salt = "";
-        while ($i < $length) {
+        while ($i < $max) {
             $salt .= $characterList{mt_rand(0, (strlen($characterList) - 1))};
             $i++;
         }

History