Jump to content

Crypt function


westminster86

Recommended Posts

Crypt uses standard MD5 encryption but can also use DES or other encryption as available. Information on the types of encryption that is available on your system can be viewed through constants set in PHP. Check for which encryption is supported by using the following code.

From http://www.devshed.com/c/a/PHP/Using-the-PHP-Crypt-Function/

 

Although you can use the crypt function with other types of encryption, you might not want to.

 

md5() does the same as crypt's default method. It's recommended not to use md5 for important data any more due to the wide availablity of rainbow tables and other brute force methods.

sha1() is a better algorithm than md5, but still not great - it's been cracked as far as I know. Either way, the US government won't use it anymore.

 

I use hash("sha512",$string); - sha512 is more secure than sha1, and you can easily update it to use other algorithms if you wish (take a look in the manual).

 

Just remember to check the length of the output. Eg sha512 outputs a 128 character string.

Link to comment
Share on other sites

DeadOnArrival: So if you used (substr(sha512($var,0,32)); so it cuts the 128 character string into a 32 character string, so long as you did whenever you post/reference that field in the db, would it protect it even more? Since you'd have to really know the whole hash to work out the original, no?

 

I use md5(sha1($var)), which seems strong enough (since the attacker would have to access the database in the first place to view the hash). 

 

Sam

Link to comment
Share on other sites

The whole point of hashing is in case someone accesses the database.... and if you cut the first 32 characters out, more than one string will match it (actually, more than one do anyway, but more then that... 4 times more I think, but don't quote me on that)

 

Instead of md5 then sha1, use sha512, but with a salt...

 

eg

<?php
$password = $_GET['password']; //Ignoring any functions to clean user input for example
$rand = rand(1,99999); //Random number 1-99999 - make it longer if you're really paranoid
$salt = md5($rand); //MD5 the salt, since it's faster than sha512 to produce a 32bit salt
$password = hash("sha512",$salt.$password); //Hash the salt and password (concatenated)
?>

 

I use this because it means any attempt to brute force the password would require one of 100,000 32-bit sequences, followed by the password. The brute forcer (unless they know what you did) doesn't know what you hashed together... and even then has to try every possible dictionary password along with every possible hash from 1-99999.

 

If you're really paranoid, make the random number longer, add the salt to each end of the password... anything you like, but remember that it all uses processor power. Sha512 itself with a short salt (not even bothering to md5 the salt) is more than enough security for most sites. Just remember to store the salt (either in its random number form -useful because the attacked doesnt know whether you md5, sha512 or sha1 etc it - or in its 32 bit form (kinda a waste of time and space)

 

Personally I store the 5 digit number and the final hash - no attacker would know what was done with the first to get to the second, makes brute forcing much harder and probably take too long for them to care.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.