Skip to main content
Inspiring
October 3, 2006
Question

OT: More about unique random passwords

  • October 3, 2006
  • 20 replies
  • 1008 views
I have a master list of passwords in a MySQL table.

I want to generate a new random password that is unique.

I am using this markup -

$passwords=array();
$rsPasswordList = mysql_query("SELECT contactPassword FROM
tblcontactdata",$selectData)
or die(mysql_errno()." : ".mysql_error());
for ($j=0; $rec=mysql_fetch_array($rsPasswordList); $j++){
$passwords[]=$rec;
}
$unique='false';
for ($i=0; $unique!='false'; $i++) {
$temp = randomkeys(8); // this is generating a random 8-character p/w
if(!array_key_exists($temp, $passwords)) {
$newPassword = $temp;
}
}

I want to make sure that this is going to produce a unique password. Can
you evaluate that for me, please?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================



This topic has been closed for replies.

20 replies

Inspiring
October 3, 2006
In the meantime, while I was waiting for the cavalry to arrive, I had found
and fixed some of those errors. Yeah, that's the ticket! 8)

Thanks, David....

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"David Powers" <david@example.com> wrote in message
news:efubo8$p28$1@forums.macromedia.com...
> Murray *ACE* wrote:
>> I want to make sure that this is going to produce a unique password. Can
>> you evaluate that for me, please?
>
> It won't work. You have several mistakes in there, the most important ones
> being the use of quotes around false, which is a keyword (see page 138 of
> "Foundation PHP for DW 8" which I know you've got). Another mistake is
> you're using mysql_fetch_array() to extract the database results.
> Consequently, $rec will always be a two item array containing the result
> both as an indexed array element and as an associative array element. The
> actual password is held in $rec[0] and $rec['contactPassword']. Also,
> you're using array_key_exists to check the passwords, but the array keys
> will be 0, 1, 2, 3, etc. In effect, $passwords will look like this:
>
> $passwords[0] = array(0 => 12345678, 'contactPassword' => 12345678);
> $passwords[1] = array(0 => 87654321, 'contactPassword' => 87654321);
> and so on.
>
> Finally, and perhaps most crucially, you never set $unique to true once a
> unique password has been generated.
>
> You need to rewrite it like this:
>
> $passwords=array();
> $rsPasswordList = mysql_query("SELECT contactPassword FROM
> tblcontactdata",$selectData)
> or die(mysql_errno()." : ".mysql_error());
> while ($rec = mysql_fetch_row($rsPasswordList)){
> $passwords[] = $rec[0];
> }
> $unique = false;
> while ($unique === false) {
> $temp = randomkeys(8); // this is generating a random 8-character p/w
> if(!in_array($temp, $passwords)) {
> $newPassword = $temp;
> $unique = true;
> }
> }
>
> I assume that randomkeys() is a custom function defined elsewhere.
>
> --
> David Powers
> Adobe Community Expert
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> http://foundationphp.com/


Inspiring
October 3, 2006
Murray *ACE* wrote:
> I want to make sure that this is going to produce a unique password. Can
> you evaluate that for me, please?

It won't work. You have several mistakes in there, the most important
ones being the use of quotes around false, which is a keyword (see page
138 of "Foundation PHP for DW 8" which I know you've got). Another
mistake is you're using mysql_fetch_array() to extract the database
results. Consequently, $rec will always be a two item array containing
the result both as an indexed array element and as an associative array
element. The actual password is held in $rec[0] and
$rec['contactPassword']. Also, you're using array_key_exists to check
the passwords, but the array keys will be 0, 1, 2, 3, etc. In effect,
$passwords will look like this:

$passwords[0] = array(0 => 12345678, 'contactPassword' => 12345678);
$passwords[1] = array(0 => 87654321, 'contactPassword' => 87654321);
and so on.

Finally, and perhaps most crucially, you never set $unique to true once
a unique password has been generated.

You need to rewrite it like this:

$passwords=array();
$rsPasswordList = mysql_query("SELECT contactPassword FROM
tblcontactdata",$selectData)
or die(mysql_errno()." : ".mysql_error());
while ($rec = mysql_fetch_row($rsPasswordList)){
$passwords[] = $rec[0];
}
$unique = false;
while ($unique === false) {
$temp = randomkeys(8); // this is generating a random 8-character p/w
if(!in_array($temp, $passwords)) {
$newPassword = $temp;
$unique = true;
}
}

I assume that randomkeys() is a custom function defined elsewhere.

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Inspiring
October 3, 2006
We've noticed....

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"crash" <crash@bcdcdigital.com> wrote in message
news:efu9rn$muq$1@forums.macromedia.com...
> which is great because communicating verbally is SO my strong suit....
>
> ;o)
>
>>I don't think so - other than voluminous commenting.
>>
>> --
>> Murray --- ICQ 71997575
>
>


Inspiring
October 3, 2006
which is great because communicating verbally is SO my strong suit....

;o)

>I don't think so - other than voluminous commenting.
>
> --
> Murray --- ICQ 71997575


Inspiring
October 3, 2006
I don't think so - other than voluminous commenting.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"crash" <crash@bcdcdigital.com> wrote in message
news:efu77o$jsu$1@forums.macromedia.com...
>I know, and, what's worse, is your server behaviors. Those are about the
>only thing I use DW for, and the best part of taking over or handing over a
>DW created site - you don't have to dig through custom code to see how data
>is being parsed.
>
> Is there any solution to that?
>
> Thanks,
>
> Jon
> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
> news:efu6pf$jaq$1@forums.macromedia.com...
>> >A bit OT, but do you typically create your own select statements instead
>> >of using the Recordsets from DW?
>>
>> Lately I have been - it's much easier to do it this way. But you
>> eliminate the Bindings panel when you do that.
>>
>> --
>> Murray --- ICQ 71997575
>> Adobe Community Expert
>> (If you *MUST* email me, don't LAUGH when you do so!)
>> ==================
>> http://www.dreamweavermx-templates.com - Template Triage!
>> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
>> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
>> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
>> ==================
>>
>>
>> "crash" <crash@bcdcdigital.com> wrote in message
>> news:efu5po$i7f$1@forums.macromedia.com...
>>>A bit OT, but do you typically create your own select statements instead
>>>of using the Recordsets from DW?
>>>
>>> I've been trying to use the recordsets, but I find them increasingly
>>> awkward for complex SQL. I'd like to still use them, though, for
>>> "maintainability" of my sites (ie, I would like to say they're made with
>>> DW pieces).
>>>
>>>
>>> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
>>> news:eftqhk$4cd$1@forums.macromedia.com...
>>>>I have a master list of passwords in a MySQL table.
>>>>
>>>> I want to generate a new random password that is unique.
>>>>
>>>> I am using this markup -
>>>>
>>>> $passwords=array();
>>>> $rsPasswordList = mysql_query("SELECT contactPassword FROM
>>>> tblcontactdata",$selectData)
>>>> or die(mysql_errno()." : ".mysql_error());
>>>> for ($j=0; $rec=mysql_fetch_array($rsPasswordList); $j++){
>>>> $passwords[]=$rec;
>>>> }
>>>> $unique='false';
>>>> for ($i=0; $unique!='false'; $i++) {
>>>> $temp = randomkeys(8); // this is generating a random 8-character p/w
>>>> if(!array_key_exists($temp, $passwords)) {
>>>> $newPassword = $temp;
>>>> }
>>>> }
>>>>
>>>> I want to make sure that this is going to produce a unique password.
>>>> Can you evaluate that for me, please?
>>>>
>>>> --
>>>> Murray --- ICQ 71997575
>>>> Adobe Community Expert
>>>> (If you *MUST* email me, don't LAUGH when you do so!)
>>>> ==================
>>>> http://www.dreamweavermx-templates.com - Template Triage!
>>>> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
>>>> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
>>>> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
>>>> ==================
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>


Inspiring
October 3, 2006
I know, and, what's worse, is your server behaviors. Those are about the
only thing I use DW for, and the best part of taking over or handing over a
DW created site - you don't have to dig through custom code to see how data
is being parsed.

Is there any solution to that?

Thanks,

Jon
"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:efu6pf$jaq$1@forums.macromedia.com...
> >A bit OT, but do you typically create your own select statements instead
> >of using the Recordsets from DW?
>
> Lately I have been - it's much easier to do it this way. But you
> eliminate the Bindings panel when you do that.
>
> --
> Murray --- ICQ 71997575
> Adobe Community Expert
> (If you *MUST* email me, don't LAUGH when you do so!)
> ==================
> http://www.dreamweavermx-templates.com - Template Triage!
> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
> ==================
>
>
> "crash" <crash@bcdcdigital.com> wrote in message
> news:efu5po$i7f$1@forums.macromedia.com...
>>A bit OT, but do you typically create your own select statements instead
>>of using the Recordsets from DW?
>>
>> I've been trying to use the recordsets, but I find them increasingly
>> awkward for complex SQL. I'd like to still use them, though, for
>> "maintainability" of my sites (ie, I would like to say they're made with
>> DW pieces).
>>
>>
>> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
>> news:eftqhk$4cd$1@forums.macromedia.com...
>>>I have a master list of passwords in a MySQL table.
>>>
>>> I want to generate a new random password that is unique.
>>>
>>> I am using this markup -
>>>
>>> $passwords=array();
>>> $rsPasswordList = mysql_query("SELECT contactPassword FROM
>>> tblcontactdata",$selectData)
>>> or die(mysql_errno()." : ".mysql_error());
>>> for ($j=0; $rec=mysql_fetch_array($rsPasswordList); $j++){
>>> $passwords[]=$rec;
>>> }
>>> $unique='false';
>>> for ($i=0; $unique!='false'; $i++) {
>>> $temp = randomkeys(8); // this is generating a random 8-character p/w
>>> if(!array_key_exists($temp, $passwords)) {
>>> $newPassword = $temp;
>>> }
>>> }
>>>
>>> I want to make sure that this is going to produce a unique password.
>>> Can you evaluate that for me, please?
>>>
>>> --
>>> Murray --- ICQ 71997575
>>> Adobe Community Expert
>>> (If you *MUST* email me, don't LAUGH when you do so!)
>>> ==================
>>> http://www.dreamweavermx-templates.com - Template Triage!
>>> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
>>> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
>>> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
>>> ==================
>>>
>>>
>>>
>>
>>
>
>


Inspiring
October 3, 2006
>A bit OT, but do you typically create your own select statements instead of
>using the Recordsets from DW?

Lately I have been - it's much easier to do it this way. But you eliminate
the Bindings panel when you do that.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"crash" <crash@bcdcdigital.com> wrote in message
news:efu5po$i7f$1@forums.macromedia.com...
>A bit OT, but do you typically create your own select statements instead of
>using the Recordsets from DW?
>
> I've been trying to use the recordsets, but I find them increasingly
> awkward for complex SQL. I'd like to still use them, though, for
> "maintainability" of my sites (ie, I would like to say they're made with
> DW pieces).
>
>
> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
> news:eftqhk$4cd$1@forums.macromedia.com...
>>I have a master list of passwords in a MySQL table.
>>
>> I want to generate a new random password that is unique.
>>
>> I am using this markup -
>>
>> $passwords=array();
>> $rsPasswordList = mysql_query("SELECT contactPassword FROM
>> tblcontactdata",$selectData)
>> or die(mysql_errno()." : ".mysql_error());
>> for ($j=0; $rec=mysql_fetch_array($rsPasswordList); $j++){
>> $passwords[]=$rec;
>> }
>> $unique='false';
>> for ($i=0; $unique!='false'; $i++) {
>> $temp = randomkeys(8); // this is generating a random 8-character p/w
>> if(!array_key_exists($temp, $passwords)) {
>> $newPassword = $temp;
>> }
>> }
>>
>> I want to make sure that this is going to produce a unique password. Can
>> you evaluate that for me, please?
>>
>> --
>> Murray --- ICQ 71997575
>> Adobe Community Expert
>> (If you *MUST* email me, don't LAUGH when you do so!)
>> ==================
>> http://www.dreamweavermx-templates.com - Template Triage!
>> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
>> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
>> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
>> ==================
>>
>>
>>
>
>


Inspiring
October 3, 2006
That's basically what I'm doing - except I am using an array function.

I just wanted to make sure that my implementation of it would verify
uniqueness.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"darrel" <notreal@nowhere.com> wrote in message
news:eftrmm$5vj$1@forums.macromedia.com...
>
>> I want to make sure that this is going to produce a unique password. Can
>> you evaluate that for me, please?
>
> Create the password, then query the DB using said password and see if it
> returns a match. If not, it's unique.
>
> -Darrel
>


Inspiring
October 3, 2006
A bit OT, but do you typically create your own select statements instead of
using the Recordsets from DW?

I've been trying to use the recordsets, but I find them increasingly awkward
for complex SQL. I'd like to still use them, though, for "maintainability"
of my sites (ie, I would like to say they're made with DW pieces).


"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:eftqhk$4cd$1@forums.macromedia.com...
>I have a master list of passwords in a MySQL table.
>
> I want to generate a new random password that is unique.
>
> I am using this markup -
>
> $passwords=array();
> $rsPasswordList = mysql_query("SELECT contactPassword FROM
> tblcontactdata",$selectData)
> or die(mysql_errno()." : ".mysql_error());
> for ($j=0; $rec=mysql_fetch_array($rsPasswordList); $j++){
> $passwords[]=$rec;
> }
> $unique='false';
> for ($i=0; $unique!='false'; $i++) {
> $temp = randomkeys(8); // this is generating a random 8-character p/w
> if(!array_key_exists($temp, $passwords)) {
> $newPassword = $temp;
> }
> }
>
> I want to make sure that this is going to produce a unique password. Can
> you evaluate that for me, please?
>
> --
> Murray --- ICQ 71997575
> Adobe Community Expert
> (If you *MUST* email me, don't LAUGH when you do so!)
> ==================
> http://www.dreamweavermx-templates.com - Template Triage!
> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
> ==================
>
>
>


Inspiring
October 3, 2006

> I want to make sure that this is going to produce a unique password. Can
> you evaluate that for me, please?

Create the password, then query the DB using said password and see if it
returns a match. If not, it's unique.

-Darrel