Solved

Random password 8-12 character unique alpha-numeric code

Posted on 2009-04-05
4
1,445 Views
Last Modified: 2013-12-12
I want to generate random password 8 - 12 character unique alpha-numeric code. How do I proceed with correct random unique ?
0
Comment
Question by:Loganathan Natarajan
  • 3
4 Comments
 
LVL 5

Accepted Solution

by:
striker46 earned 250 total points
ID: 24075008
This is just a simple idea I've seen used in some sites.

Gets current timestamp, md5's it and gets the number of characters you desire from the beginning of the resulting string.

There are better ways to achieve the results but this one is fairly good and simple. Chances that a unique password is generated twice are extremely low because MD5 is always completely different for each timestamp.

$chars = 8;
$pwd = md5(time());
 
$rest = substr($pwd, 0, $chars - 1);
 
echo $pwd;

Open in new window

0
 
LVL 5

Expert Comment

by:striker46
ID: 24075010
Wrong variable name. Again:


$chars = 8;
$pwd = md5(time());
 
$pwd= substr($pwd, 0, $chars - 1);
 
echo $pwd;

Open in new window

0
 
LVL 36

Author Closing Comment

by:Loganathan Natarajan
ID: 31566918
thanks
0
 
LVL 5

Expert Comment

by:striker46
ID: 24137979
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question