Logo
Generate An Authentication Code
Online Now: 0
Snippet Code
This basic snippet will create a random authentication code, or just a random string.
<?php
# This particular code will generate a random string
# that is 25 charicters long 25 comes from the number
# that is in the for loop
$string "abcdefghijklmnopqrstuvwxyz0123456789";
for(
$i=0;$i<25;$i++){
    
$pos rand(0,36);
    
$str .= $string{$pos};
}
echo 
$str;
# If you have a database you can save the string in 
# there, and send the user an email with the code in
# it they then 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
?>
 
Snippet Comments

Add Your Comment

IT companies in Toronto
2011-06-22 19:50:32
The code works very well. I have used it at work with great success. The programmers did such a great job with it.
The code is so good on this. There is so much that you can do on it.
Supra For Sale
2011-06-13 23:40:24
Construction on the new plant will start next month. Chrysler also said that state-of-the-art axles are coming off the line sometime in 2010. Chrysler will break ground on a new engine plant in Detroit suburb of Trenton next and will announce several more plant investments in the weeks to come. However the locations were not disclosed.
attorney
2011-02-08 02:59:01
Thanks that code is really useful for me.
develophp
2010-11-24 11:36:37
Forgot to add this to my previous reply...

@php_scripts You should read here http://php.net/manual/en/function.rand.php
develophp
2010-11-24 11:34:36
I think you guys are mixing up the hash char lengths

MD5 = 32 chars
SHA1 = 40 chars

My current activation key generator is this
$key = md5(uniqid(time(), TRUE));
php scripts
2010-09-14 00:29:43
rand() in not a real random function i think. you can use MD5 or SHA1 hash to generate An Authentication Code.
Sam Yong
2009-07-25 00:00:00
I agree with Wilson. you can just simply use an md5 to generate a random string. $rand_string = substr(md5(time() . mt_rand()),0,40);
Wilson
2009-02-03 00:00:00
It might be just as easy to create a string like this that could be inserted into a db:
$id = md5(uniqid(rand(), 1)); (40 characters)

This would be more secure if using it for a forgotten password email and being compared to in a database.

Add Your Comment

 
Snippet Tools
Rate this Snippet:

Rate the difficulty level:

Request Snippet Update


Suggested Difficulty Level: Novice
Current Score: 2.71
Total votes: 270
Total Views: 7449

Other top snippets by admin:

1. JPEG to ASCII Converter
2. Add (th, st, nd, rd, th) to the end of a number
3. Dynamic Page Content From Links
4. AJAX Quickie
5. Simple Image CAPTCHA

Search
Search for:







User Panel

User name:

Password:

Register And Post Your Own Snippets

New Snippets

1.  Shorten text and (4 of 1)

2.  file-based simple guest (0 of 0)

3.  adding an entry (0 of 0)

4.  integer to currency (1.33 of 3)

5.  Aggregate IP addresses (0 of 0)

6.  file handling (0 of 0)

7.  testing system with (0 of 0)

8.  Make an php (1 of 1)

9.  allow download in (5 of 1)

10.  redirect in 3 (0 of 0)

11.  live clock with (0 of 0)

12.  visit counter (3.5 of 2)

13.  contact form with (4 of 1)

14.  show a specific (0 of 0)

15.  The & sign (0 of 0)

16.  static variable in (0 of 0)

17.  multiplication table with (0 of 0)

18.  function with multiplicationt (0 of 0)

19.  php generated menu (0 of 0)

20.  drawing a table (0 of 0)

21.  embedded array (one (0 of 0)

22.  checks the week (0 of 0)

23.  put links on (4.5 of 2)

24.  Directory Image Gallery (0 of 0)

25.  TOS (4 of 1)

Home | Forum | Free PHP Web Hosting | Contact | Terms & Conditions |  
Donate
PHPSnips.com - ©2012 Amethyst Creative