Skip to content

Instantly share code, notes, and snippets.

@dahnielson
Created August 6, 2010 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dahnielson/512192 to your computer and use it in GitHub Desktop.
Save dahnielson/512192 to your computer and use it in GitHub Desktop.
Generate salt
<?php
/**
* This function generates a password salt as a string of x characters
* ranging from a-zA-Z0-9.
*
* @param $max integer The number of characters in the string
* @author AfroSoft <scripts@afrosoft.co.cc>
*/
function generate_salt($max = 40)
{
$character_list = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$salt = "";
for ($i = 0; $i < $max; $i++)
$salt .= $character_list{mt_rand(0,strlen($character_list)-1)};
return $salt;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment