Our Scripts Vault contains many game scripts that you can use to create your own game!
<?phpif ($_POST){$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()_+=';$value = 1;// Generate a random character stringfunction rand_str($chars){ //sets the variables as global global $string,$length,$chars; //sets the length of the string as a random length $length = mt_rand(20,60); // Length of character list $chars_length = (strlen($chars) - 1); // Start our string $string = $chars{mt_rand(0, $chars_length)}; // Generate random string for ($i = 1; $i < $length; $i = strlen($string)) { // Grab a random character from our list $r = $chars{mt_rand(0, $chars_length)}; // Make sure the same two characters don't appear next to each other if ($r != $string{$i - 1}) $string .= $r; } // Return the string return $string;}function w_str(){ //sets the variables as global global $string,$chars; // the for loop which'll generate 120 random salts for ($value=1; $value <= 120; $value++){ //This calls forth our super function rand_str($chars); //this opens up the file to write to global $value,$string,$chars; $fp = fopen('data.txt', 'w'); //this writes teh data to teh file fwrite($fp,$value.":".$string."\n"); fclose($fp);}}w_str();}?><form method="post" action="hashmaker.php"><input type="text" name="blah" /><input type="submit" value="create salt"/></form>
echo 'I\'m a sentence followed by a line break!' . PHP_EOL;
global $string,$length,$chars; global $string,$chars; global $value,$string,$chars;....come on , no need, make them either parameters of the function or constants (those that won't change of course)$length = mt_rand(20,60); ...the limit/range should be a parameter tooad linebreakes....which OS? for Win try \r\n...not sure if it'll work, but that's the way it handles newlines
fwrite($fp,$value.":".$string."\r\n");
fwrite($fp,$value.":".$string.PHP_EOL);
Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
Why would you want a list of random salts? Why not just append the user's name to their password before hashing? Is there a purpose for salting besides defeating rainbow tables that I'm forgetting?
You are, indeed, correct. The only problem with making the salt the equivalent of the username or something else account-dependent is that it's easy to guess. Of course, you also need to store the salt somewhere unless you're using a static list of salts at specific intervals.Using a file to store the available salts keeps the salt separate from the account information. If your account table is compromised, the attacker is likely to try hashing combinations of account information with their rainbow table to produce the desired hash. Assuming they're that dedicated to the pursuit.However, if you have, say, 120 salts that you recycle based on a simple algorithm (uid % 120 = salt index) then you have a reliable means of determining the salt of a user account without a need to store it with the account information.Now, you'd probably want to cache an object like this in your cache table (which still serves the purpose of keeping it separate from the account table) so that you don't need to constantly take the performance hit of reading the file contents. But, it just added an extra layer of security to the users passwords.However, this scheme would still render the same hash if the users had the misfortune of choosing the same password and happened to be an increment of 120 accounts away because they'd be using the same salt. So, you should also count the account creation time + account name, or some other unique account feature to generate the salt. But, for greatest security, you should not have your salts based solely upon account information as that makes them easier to crack.For greatest security, you should randomize your salts from time to time. You can do this by setting up a new set of salts. Then, you create an additional table specifying the user's current salt version. When the user attempts to authenticate, you pull their current salt object and test against that. If it's successful, you re-generate their password hash with your current salt object.In this manner, you can shorten the attack window if your database is compromised. At least, for those accounts that are active.
Also the idea of the static salt using the exact time that the user logged in or created the account sounds a bit odd to me atleast.
For my static salt, i was going to generate one extra random salt and just use that as my static salt once again changing it out every maintenance.
The other thing was/is going to be, the safest way to store said value for the salts is to just use the number corresponding to said random salt correct?
$static_salt.$password.$random_salt and then hashing that. Is that any more secure or less secure than any other combination?
edit:And since it seems that php in and of itself is pretty fast with regards to radnomly generating this data(atleast on my home pc), about how many random salts should i use? Since i'm already using 3 digits, would 400 be out of the question? It apparently generates 401 in .243 seconds.
Just being curious- are you using MD5 to encrypt and has anyone else heard that rainbow table attacks less effective against SHA encryption? I keep seeing little blurbs on switching MD5 to SHA because of this, and really getting curious. (I switched over to SHA because I figured at least it couldn't hurt, and use a little salt (typically a 32 char random string) changing/updating too, but not to the degree that you are talking)
It just seemed odd to me to just store it inside of the database since the hacker if he gets ahold of only the databases(i'm of course going to try to do everything in my power to prevent them from doing so), they'd only have to guess the "nonce" as you call it.
edit: But the problem i see is that they dont' let you specify how much of a delay you want to use... so i'm worried about that much.
the only way to protect the user in this case is if your "nonce" or static salt is stored in an external file that is inaccessible to any user that is also allowed to read the source files. Personally, I'm unable to think of a way this is even possible that's unable to be determined by the cracker.
Although, I would still be a proponent of a set of nonces rather than a single nonce. If the single nonce is such a common scheme and salts are stored in the table alongside pass hashes, they have only to guess a single nonce to crack the database. However, if you're using a set of nonces that you can simply map to a particular user account (anything more complex than a single mathematical expression such as $nonceIndex = $userField % $maxNonces is probably open to exploits) then the attacker has to also correctly guess a different nonce for each account.
I'd like to point out that no system is 100% secure. The goal of internet security is to throw so many roadblocks in the path of a would-be cracker that they'd prefer to spend their time cracking a less secure website.
You couldn't do that with an interpreted language in the first place, since the user who owns the process needs to be able to both read the source (to execute it) and read the data files (so the process started by the user can access them).
The thing I was arguing against as pointless complexity was the idea of having rotating nonces over time rather than a fixed list of them. (Which fails your criterion of a simple account => nonce mapping.)
You don't have to outrun the lion, you just have to outrun the guy next to you...