coffeedemon
10-27-2003, 05:48 AM
I used md5 to hash (encrypted) my passwords in my database; but if someone gets access to my database they can run the hashed(encrypted) passwords against the script to hack in. To prevent this I do a custom scramble of the md5() hash.
Lets use the example of a user signing up on my site; in which I store his user name and password in my database.
Lets say he signed up with the password "mypassword"
I send "mypassword" through a scrample function:
<?php
function encrypt($e_pssd)
{
$input_md5 = md5($e_pssd); // creates a hash
$create_encryption = rand(100,199); // produces a random number between 100 and 199
$create_encryption .= $input_md5; // adds hashed password to the variable
$create_encryption .= rand(100,199); // produces a random number between 100 and 199
$encrypted_pssd = $create_encryption;
return $encrypted_pssd;
}
// encrypted("mypassword") will return:
// 10534819d7beeabb9260a5c854bc85b3e44157
?>
md5() always returns a 32-character hexadecimal number - so no matter how long the str the hash will be 32 charactors long. what this does is add three random numbers between 100 and 199 on the end of the md5 encrypted password. md5() takes any str and
so who ever gets in my database to retrieve the passwords will get (depending on your scramble) a md5() hash with characters thrown in it. This will make it impossible to figure out what string of charaters he has to use.
To unscramble passwords you pull out for a login I made another function "cleaning" out the md5() hash.
<?php
function decrypt($d_pssd)
{
$clean_decrypt = substr($d_pssd, 3, 32); // returns the string with the hash with out the first and last three numbers. revealing the actual hash.
$decrypted = $clean_decrypt;
return $decrypted;
}
$unscrambled = decrypt('10534819d7beeabb9260a5c854bc85b3e44157');
?>
$unscrambled will return with the first three characters and last three characters left out. giving the clean (unscrambled) md5() hash.
you can make things even more complicated by spliting up the md5() hash in several parts and inputing random numbers and then unscramble by spliting the scrambled md5() hash and removing those random numbers.
I hope I made this clear enough.
Any comments welcome.
Lets use the example of a user signing up on my site; in which I store his user name and password in my database.
Lets say he signed up with the password "mypassword"
I send "mypassword" through a scrample function:
<?php
function encrypt($e_pssd)
{
$input_md5 = md5($e_pssd); // creates a hash
$create_encryption = rand(100,199); // produces a random number between 100 and 199
$create_encryption .= $input_md5; // adds hashed password to the variable
$create_encryption .= rand(100,199); // produces a random number between 100 and 199
$encrypted_pssd = $create_encryption;
return $encrypted_pssd;
}
// encrypted("mypassword") will return:
// 10534819d7beeabb9260a5c854bc85b3e44157
?>
md5() always returns a 32-character hexadecimal number - so no matter how long the str the hash will be 32 charactors long. what this does is add three random numbers between 100 and 199 on the end of the md5 encrypted password. md5() takes any str and
so who ever gets in my database to retrieve the passwords will get (depending on your scramble) a md5() hash with characters thrown in it. This will make it impossible to figure out what string of charaters he has to use.
To unscramble passwords you pull out for a login I made another function "cleaning" out the md5() hash.
<?php
function decrypt($d_pssd)
{
$clean_decrypt = substr($d_pssd, 3, 32); // returns the string with the hash with out the first and last three numbers. revealing the actual hash.
$decrypted = $clean_decrypt;
return $decrypted;
}
$unscrambled = decrypt('10534819d7beeabb9260a5c854bc85b3e44157');
?>
$unscrambled will return with the first three characters and last three characters left out. giving the clean (unscrambled) md5() hash.
you can make things even more complicated by spliting up the md5() hash in several parts and inputing random numbers and then unscramble by spliting the scrambled md5() hash and removing those random numbers.
I hope I made this clear enough.
Any comments welcome.