Re: Create passwords for multiple records (PHP/mySQL)



On 26 Sep, 07:01, r0g <aioe....@xxxxxxxxxxxxxxxxxx> wrote:
wozza wrote:
hi

I'm a Dreamweaver user who's created a few simple data entry/
registrations forms in my time, but I'm not really a coder (though I
can follow instructions and am not afraid to dabble...) - I generally
make use of DW's builtin commands and some extensions.

Anyway I'm creating a registration site for event exhibitors and I've
been asked to come up with a method of automatically generating
passwords for inserted records, either as they're inserted or at some
point later (i.e. some kind of mass password creation). Is there a
recognised way of populating multiple records' password fields with
random passwords (say 8 characters long)?

A couple of possible complications...

1. The client wants to be able to insert the rest of the exhibitor
data via a CSV upload (I'm using a Dreamweaver extension for this -
http://www.felixone.it/extensions/prod/mxiecsven.asp) as well as
creating individual records manually via the registration site.

2. They've also asked that the password avoids letter 'O' and numner
'0'.

Thanks in advance!

There's no standard way as it's pretty trivial to write a function to
generate random strings. This is what I use...

  function rseq($x)
    {
      # Returns string of random alphanumeric characters of specified
length $x
      # Note - mtrand (mersenne twister) used as rand not actually very
random at all!
      $d = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
      $dl = strlen($d)-1;
      $s = '';
      for($i = 0; $i < $x; $i++)
        {
          $s .= $d[(mt_rand(0,$dl))];
        }
      return $s;
    }

Just lose the O's and 0's from $d. Do also note that this uses mt_rand
as PHP's normal random number generator is REALLY REALLY AWFUL.

Not sure what you mean when you say 'insert the rest of the exhibitor
data via a CSV upload'... What do they have and what do they want you to
do with it?

Regards,

Roger.- Hide quoted text -

- Show quoted text -

Thanks for the replies guys. I've now decided to go a differetn route
in add the passwords to the records. Basically after inserting the
contents of a CSV (via that 3rd party extension for Dreamweaver I
mentioned) the browser is redirected to a php with the following
code:

<?php require_once('../Connections/connExhibiting.php'); ?>
<?php
mysql_select_db($database_connExhibiting, $connExhibiting) or
die(mysql_error());

function genRandomString() {
$length = 8;
$characters = "123456789abcdefghijklmnpqrstuvwxyz";

for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}

return $string;
}

$query = "SELECT ID, password FROM tblUsers";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result)) {
$id = $row['ID'];
$password = $row['password'];

$genPassword = genRandomString();

$sql_update = "UPDATE tblUsers SET password = '$genPassword' WHERE
(password = '' OR password is NULL)";
mysql_query($sql_update) or die(mysql_error());
}
?>
<?php
mysql_free_result($result);
?>

It _almost_ works, except the password is the same for all records - I
need the string returned by genRandomString() to be different for each
record - any help would be appreciated!

Cheers
.



Relevant Pages