I have a pssword variable where it contains the user’s password which contains some stirngs at the start and end of the password so that it salts the password. Below is the code for this:
$teacherpassword = md5(md5("j92".$teacherpassword."djS"));
Obviously the characters chosen to salt the password would be the same character for all the passwords.
What I want is to create a random characters generator so that the first 3 characters and the last 3 characters of the salt are all random so each password will have a random salt.
Below is the php generator create to pick out characters at random for the salt:
$salt = "";
for ($i = 0; $i < 40; $i++) {
$salt .= substr(
"./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
mt_rand(0, 63),
1);
}
My question is that how do I get the generator to pick out 6 random characters for the salt, and then stick 3 of those characters in front of the passowrd and th other 3 at the end of the password?
FOR EXAMPLE:
PASSWORD 1 could be: $teacherpassword = md5(md5(“jfs”.$teacherpassword.”sfS”));
PASSWORD 2 could be: $teacherpassword = md5(md5(“4f3″.$teacherpassword.p.S”));
PASSWORD 3 could be: $teacherpassword = md5(md5(“wpw”.$teacherpassword.”qq2″));
As you can see all passwords contain their own salt thanks to the php random generator for the salt
A really simple solution would be to use
substr()One more suggestion for you would be to use PHP’s
uniqueid()function to generate random salt for your passwords.