[PHP] salt? crypt? md5? howto :-)

Newbie Spellweaver
Joined
Apr 10, 2008
Messages
5
Reaction score
0
Hey!
Any documents that explains what is salt, how to use encrypt functions and add encrypted passwords to database and then compare with input entered password? :]

Thanks a lot, hope it will not takes too much time to answer me, other way i can already figure it out myself :]
 
And yet my question on the official resource of PHP is not present so there's no answer, only dummy examples of each function.

You probably feel yourself Zend Masters if you know even the PHP's website.

Anyway, you guys been here too much, and your brain probably preprocessored, what is the point of sending people to resources? for what this forum is exists? to tell people go to http:// ?
Hell with that, if you dont know the answer, wait for another person to answer and learn from him too, it is not ashame even for 'Mega' Users like you.
 
And yet my question on the official resource of PHP is not present so there's no answer, only dummy examples of each function.

You probably feel yourself Zend Masters if you know even the PHP's website.

Anyway, you guys been here too much, and your brain probably preprocessored, what is the point of sending people to resources? for what this forum is exists? to tell people go to http:// ?
Hell with that, if you dont know the answer, wait for another person to answer and learn from him too, it is not ashame even for 'Mega' Users like you.

I guess you have never searched thru the articles only thru functions eh ? And yes the resources are to use them, whats the point of explaining it myself if professionals already did it, or copying n pasting it ? I do not consider myself as a mega user, and your post was even more unecessary and pointless than ours. So please if you consider yourself as a new user do not offend people at very beggning, i guess it's not a good way to introduce yourself.

P.S. Who the hell said i do not know the answer, and going further i know it because i found it on the php.net repository.
 
Anyway, you guys been here too much, and your brain probably preprocessored, what is the point of sending people to resources? for what this forum is exists? to tell people go to http:// ?
Hell with that, if you dont know the answer, wait for another person to answer and learn from him too, it is not ashame even for 'Mega' Users like you.

We do not want our forum to decrease into a basic help forum where people cannot search. We have better things to do, we want to help you ONLY if you do some investigation yourself too. Lazyness will be punished.

Using the hashes is fairly easy, let me quote it from php.net:

PHP:
 <?php
$str = 'apple';

if (md5($str) === '1f3870be274f6c49b3e31a0c6728957f') {
    echo "Would you like a green or red apple?";
    exit;
}
?>
</div> </div>
PHP:
 <?php
$str = 'apple';

if (sha1($str) === 'd0be2dc421be4fcd0172e5afceea3970e2f3d940') {
    echo "Would you like a green or red apple?";
    exit;
}
?>
</div> </div>

Salting is even more difficult, append a certain string to the to-be-hashed string, and hash that.

sha1($str.'secretsalt');
 
And yet my question on the official resource of PHP is not present so there's no answer, only dummy examples of each function.

You probably feel yourself Zend Masters if you know even the PHP's website.

Anyway, you guys been here too much, and your brain probably preprocessored, what is the point of sending people to resources? for what this forum is exists? to tell people go to http:// ?
Hell with that, if you dont know the answer, wait for another person to answer and learn from him too, it is not ashame even for 'Mega' Users like you.


Wow, if thats not an extremely self centered and ignorant post I don't know what is...

I would suggest learning how to use php.net to your advantage, its a very useful resource for just about any PHP dev.
 
For encrypting with md5, Its really simple, Lets say someone has just posted a password that needs encrypting in md5, It would just be:

PHP:
$pass = md5($_POST['pass_word']);

Now if you want to salt the md5, You would need to something like:

PHP:
$salt = "This";
$pass = "And";
$second_pass = "That";

$salted_password = md5($salt.$pass.$second_pass);

Above is if you want to get carried away and double salt, 1 salt is plenty good enough though.

Cant help with crypt(), Never had the need to use it.
 
For encrypting with md5, Its really simple, Lets say someone has just posted a password that needs encrypting in md5, It would just be:

PHP:
$pass = md5($_POST['pass_word']);
Now if you want to salt the md5, You would need to something like:

PHP:
$salt = "This";
$pass = "And";
$second_pass = "That";

$salted_password = md5($salt.$pass.$second_pass);
Above is if you want to get carried away and double salt, 1 salt is plenty good enough though.

Cant help with crypt(), Never had the need to use it.

It's actually hashing, not really encryption as far as I know.

I would recommend using sha1 or something along those lines, also I would recommend using 2 salts (My version of a salt is a randomly generated string of x length.).

I actually do something to the salts, in the code while its hashing. This way, if some one gets my database, all they have are the 2 salts, and the hashed password but they know not which order the items need to be hashed, or what I did to the salts. It's not needed, but I personally think its worth the extra security.
 
Ok, so im learning this too, so it'd be:

PHP:
$pass = md5($_POST['passw']); //User input
$pass2 = md5('secret'); //What the password needs to be

if ($pass == $pass2) {
     echo "Success!";
}

Correct me if im wrong.

For encrypting with md5, Its really simple, Lets say someone has just posted a password that needs encrypting in md5, It would just be:

PHP:
$pass = md5($_POST['pass_word']);

Now if you want to salt the md5, You would need to something like:

PHP:
$salt = "This";
$pass = "And";
$second_pass = "That";

$salted_password = md5($salt.$pass.$second_pass);

Above is if you want to get carried away and double salt, 1 salt is plenty good enough though.

Cant help with crypt(), Never had the need to use it.
 
Yes, that is right, you have to save the hashed string in the database.
 
Back