Jump to content

Archived

This topic is now archived and is closed to further replies.

brown2005

Random Password

Recommended Posts

Hi is this the best function for a Random Password or is there a better one...

function makeRandomPassword()
{

$salt = "abchefghjkmnpqrstuvwxyz0123456789";

srand((double)microtime()*1000000); 

$i = 0;

while ($i <= 7)
{
 
$num = rand() % 33;

$tmp = substr($salt, $num, 1);

$pass = $pass . $tmp;

$i++;

}

$pass = md5($pass);
     
return $pass;
     
}

Share this post


Link to post
Share on other sites
yes in the $salt bit

[code]
$salt = "abchefghjkmnpqrstuvwxyzABCHEFGHJKMNPQRSTUVWXYZ0123456789";

[/CODE]

and change the first $num line to
[code]
$num = rand() % 56;

[/code]

Share this post


Link to post
Share on other sites
[quote author=paul2463 link=topic=110380.msg446088#msg446088 date=1159892641]
and change the first $num line to
[code]
$num = rand() % 56;
[/code]
[/quote]

What would that help?

Share this post


Link to post
Share on other sites
sorry that was me misunderstanding the function, i thought it was the maximum number required whilst working over $salt, which is about 33 characters long, and putting the extra capitals in makes it 54....having checked it doesnt matter.

Share this post


Link to post
Share on other sites
An easy version could be: [code]<?php
function random_password($length=8)
{
return substr(md5(microtime()),0,$length);
}
?>[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.