I have been looking into replacing SHA1 as the encryption of passwords with possibly bcrypt or something similar, and I cant seem to find a step-by-step, easy to follow tutorial for implementing this. I did a quick tutorial on youtube which produced the following code:
$username = 'myusername';
$password = 'pa55w0rd';
$str = substr($username, 0, 6);
$salt = '$2a$12$rU8E3fsI9rsKh3V2'.$str.'$';
$pass = crypt($password, $salt);
echo $salt . '<br>' . $pass;
and when I run the code in the browser, this get output:
$2a$12$rU8E3fsI9rsKh3V2myuser$
$2a$12$rU8E3fsI9rsKh3V2myuseeMSOT1BADLFs/ncqHx5aG2q953uqp.Tu
QUESTION 1:
Am I correct in assuming that both strings are generated for a user, and that both strings are required to be stored in, for example, the users table as columns "salt" and "pass"?
QUESTION 2:
Why does it look like part of the username is visible within the salt and the pass? Is this normal, or is there some additional step I need to take to eliminate this from happening?
QUESTION 3:
Is this approach to hashing passwords more secure than md5 and sha1, or is there a better approach that I should be using?
Any suggestions appreciated..