Generate Salt Random String in PHP

Nowadays, there are many web sites and e-business websites improve security level on authentication user or process business. They  add one layer password security beside hashing password (like md5). It is known as Salt. Sort of view, salt is random 6-16 characters ( from 48 to 128 bits lengths).

This is how it works in PHP:

function generateSalt($length=6)
return substr(str_shuffle($chars),0,$length);

And this is how it’s combined with md5:

function hashPassword($password,$salt)
return md5($salt.$password);

Now, you can store the hashPassword on your database, and REMEMBER to create salt field to store the $salt character too on that database so you can use it to process the password later.

Is this helpfull? Feel free to submit some comments..

Categories: IT | Tags: , , | Leave a comment

Post navigation

Tinggalkan Jejakmu berupa komen

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at

%d bloggers like this: