0

The script is surpose to encrypt a password so that it is much harder to use rainbowtables on it and there for people cannot hack the server so easily, but i cant seem to get it to work so i hope one of you can help me.

<?php

function enc($string){
    $salt = "randomsalt";
    $hash = sha1(md5($salt.$string)) . $md5($string) . sha1(md5(md5($string)));
    return $hash;   
}

echo enc('password');

?>
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
  • 1
    What do you mean it doesn't work? What does it do, and what are you expecting it to do? – glomad Jan 10 '13 at 22:17
  • 6
    **Hashing != encryption** – SLaks Jan 10 '13 at 22:17
  • 3
    SHA1 and MD5 are both broken. Use bcrypt. – SLaks Jan 10 '13 at 22:18
  • You must use a different salt for each user. – SLaks Jan 10 '13 at 22:18
  • 3
    double\triple hashing makes it less secure not more –  Jan 10 '13 at 22:24
  • possible duplicate of [How long should my password salt be, and is SHA-256 good enough?](http://stackoverflow.com/questions/3191690/how-long-should-my-password-salt-be-and-is-sha-256-good-enough) AND http://stackoverflow.com/questions/401656/secure-hash-and-salt-for-php-passwords and ... –  Jan 10 '13 at 22:28

2 Answers2

1

Listen to the comments, but you also have a typo:

$md5($string) needs to be md5($string) (it's not a variable, it shouldn't have a $ in front of it).

It's true that you're not encrypting here, but that's just a nomenclature issue (you're hashing it, which is what you want to do)... however, your salt probably shouldn't be a fixed string... it should vary by user if you really want a strong hash. There's a lot more to say on this subject (md5 and SHA1 aren't the best hash algorithms for passwords as there are too many rainbow tables for both and they're too fast to execute), but you can read up here and here for bcrypt info.

Community
  • 1
  • 1
Ben D
  • 14,321
  • 3
  • 45
  • 59
0
$md5( $string)

breaks your code. Remove the $

You should use something like bcrypt and different salts for all your users.

Green Black
  • 5,037
  • 1
  • 17
  • 29