By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,175 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

Create passwords for multiple records (PHP/mySQL)

P: n/a
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!
Sep 25 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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!
No standard way, but lots of different ways to generate passwords. Try
googling for

"password generator" php

You'll get lots of ideas.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Sep 25 '08 #2

P: n/a
On 25 Sep, 13:27, wozza <warren...@googlemail.comwrote:
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!
So you want to generate random passwords without the letter 0/number 0

A simple solution would be to generate a hash of the data along with a
secret salt - say

$password=str_replace('0', 'g', substr(sha1($data . 's3cr3t'),
0,8)); // sha1 is hex encoded i.e. 0-9,a-f

Or if you want a more random solution with more emphasis on
letters....

$chars=explode(',',"a,b,c,d,e,f,g,h,i,j,k,m,n,p,q, r,t,u,x,y,z,
2,3,4,5,6,7,8,9,!,$,%,&,*,@,#"); // for niceness I've also omitted l
(L) and 1 (one)
shuffle($chars);
$password=substr($chars,0,8);

C.
Sep 25 '08 #3

P: n/a
Message-ID:
<3a**********************************@l43g2000hsh. googlegroups.comfrom
wozza contained the following:
>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'.

What you are asking is not a major task for a coder and that's the
problem with DW generated code isn't it? You are fine until you want
something a bit different. In this case you may be better off paying
for an hour or so of a coder's time.

For the passwords, there are any number of scripts you could use. I
like to use a randomly chosen keyword (taken from a pool that I create
to suit the website) plus a randomly generated number between 0001 and
9999. This is reasonably secure as well as being fairly human friendly.
It's a good idea to make sure the username is unique, that way the
password need not be.
Here's the function I use, here with words which suit a financial theme
<?php
function passgen(){
$words=array("business","entrepreneur","economy"," bank","finance","money","shares","incubate","credi t","invoice","director","efficient","workplace","o ffice",
"sales","projection");
$key=array_rand($words);
$num=rand(1,9999);
$password=$words[$key].$num;
return $password;
}

echo passgen();

?>

See http://4theweb.co.uk/test/test.php
--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
http://slipperyhill.co.uk - http://4theweb.co.uk
Sep 25 '08 #4

P: n/a
r0g
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 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ0123456789";
$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.
Sep 26 '08 #5

P: n/a
On 25 Sep, 14:03, "C. (http://symcbean.blogspot.com/)"
<colin.mckin...@gmail.comwrote:
On 25 Sep, 13:27, wozza <warren...@googlemail.comwrote:
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!

So you want to generate random passwords without the letter 0/number 0

A simple solution would be to generate a hash of the data along with a
secret salt - say

$password=str_replace('0', 'g', substr(sha1($data . 's3cr3t'),
0,8)); // sha1 is hex encoded i.e. 0-9,a-f

Or if you want a more random solution with more emphasis on
letters....

$chars=explode(',',"a,b,c,d,e,f,g,h,i,j,k,m,n,p,q, r,t,u,x,y,z,
2,3,4,5,6,7,8,9,!,$,%,&,*,@,#"); // for niceness I've also omitted l
(L) and 1 (one)
shuffle($chars);
$password=substr($chars,0,8);

C.
Whoops - last line should be

$password=substr(implode('',$chars),0,8);

C.
Sep 26 '08 #6

P: n/a
On 26 Sep, 07:01, r0g <aioe....@technicalbloke.comwrote:
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 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ0123456789";
* * * $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
Oct 2 '08 #7

P: n/a
On Sep 26, 7:01*am, r0g <aioe....@technicalbloke.comwrote:
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 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ0123456789";
* * * $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)) {

$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
Oct 2 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.