By 05/02/2014 17 Comments

How to generate Authentication code in PHP

What is an Authentication?

  • It is a mechanism for login system
  • A user can login to your website that is called an authentication
  • End-user has been authenticated before entering in your website by using login system
  • The authentication should be strong
  • The following PHP code defines very basic authentication example

This code will generate a random string that is 25 charicters long 25 comes from the number that is in the for loop.


$string = "abcdefghijklmnopqrstuvwxyz0123456789"; // this is the string which will be randomly encrypted

for($counter=0; $counter<25; $counter++) // loop through each string characters

$position = rand(0,36); // random function which generate random numbers in every execution and assign these into $position variable

$authstr .= $string{$position}; // random numbers merge with actual string, create a random series then assign and concat to $authstr variable


echo $authstr ; // display that random string series in webpage


If you have a database you can save the string in there, and send the user an email with the code in it,then they can click a link or copy the code and you can then verify that that is the correct email or verify what ever you want to verify.

Posted in: PHP

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .