Hello :) I'm a hobbyist too, and I think I can point you in the right direction, despite not knowing much about how the magic happens.
1) user enters his password, program encrypts using a certain method, and THAT encrypted password gets saved.
2) bam. NOBODY can see what the original was - not even the user who entered it. At login, that operation is repeated and "whatever the user entered for login" password gets encrypted by the same process and then it is compared with the also encrypted saved password. They should match if they were the same unencrypted original.
Well
For extra security, something called a "salt" is sometimes "added" to the encryption process, to make it yet harder to crack the password. Say somehow someone got hold of your encryption code AND encrypted passwords list, and tries to revert the process by reverse engineering your code? Well, now that person has the extra job of finding what your "salt" was... (it could be a string saved in your server, a clever "playing with dates of the month" trick, etc... many options). This is what I remember from what I read. Plenty of pointers to get you started. And more:
I use this: which I got from somewhere in the internet years ago
function encryptTheString($password, $salt, $iter_count=4096, $keylen=64, $hash_alg= 'sha256' )
{
// Compute the length of hash alg output.
// Some folks use a static variable and save the value of the hash len.
// Considering we are doing 1000s hmacs, doing one more won't hurt.
$hashlen = strlen(hash($hash_alg, null, true));
// compute number of blocks need to make $keylen number of bytes
$numblocks = ceil($keylen / $hashlen);
// blocks are appended to this
$output = '';
for ($i = 1; $i <= $numblocks; ++$i) {
$block = hash_hmac($hash_alg, $salt . pack('N', $i), $password, true);
$ib = $block;
for ($j = 1; $j < $iter_count; ++$j) {
$block = hash_hmac($hash_alg, $block, $password, true);
$ib ^= $block;
}
$output .= $ib;
}
// extract the right number of output bytes
return substr($output, 0, $keylen);
}
And a call like
$ePassword=ANDYETpbkdf2($password,"111111111122222222223333333333444444444455555555566666666661234");
Would be perfectly ok :) give sha256 a reading for the start of further enlightenment.