Re: [PHP] Regular Expression Help: genreate alphanumeric, 8 chars

2003-11-28 Thread David T-G
Adam --

...and then Adam i Agnieszka Gasiorowski FNORD said...
% 
...
%   How about,
% 
%  $password = strtolower(substr(md5(uniqid(time())), 0, 7));

Hey, that's pretty slick.  Good one!  Gonna have to remember that; it's
an excellent trick.


Thanks  HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



pgp0.pgp
Description: PGP signature


[PHP] Regular Expression Help: genreate alphanumeric, 8 chars

2003-11-27 Thread Shaun
Hi,

I need to generate a lowercase alphanumeric passwrord thats 8 characters
long, has anyone got a function that can do this?

Thanks for your help

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular Expression Help: genreate alphanumeric, 8 chars

2003-11-27 Thread David T-G
Shaun --

[No need to post twice...]

...and then Shaun said...
% 
% Hi,

Hi!


% 
% I need to generate a lowercase alphanumeric passwrord thats 8 characters
% long, has anyone got a function that can do this?

This isn't really a regular expression question, since you'd use an
expression to check if a string matched your requirements but not to
generate such a string.

A function should be easy: just loop 8 times over spitting out a random
char between a and z or 0 and 9 (use rand() to generate a number between
0 and 35 and then map that to the char).


% 
% Thanks for your help

Enjoy :-)


HTH  HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



pgp0.pgp
Description: PGP signature


Re: [PHP] Regular Expression Help: genreate alphanumeric, 8 chars

2003-11-27 Thread Bogdan Stancescu
...as in...

?
  // Could've been done with ASCII sets, but this way
  // you can easily tweak the eligible characters.
  $eligible='abcdefghijklmnopqrstuvwxyz0123456789';
  $pwdLen=8;
  $password='';
  for($i=0;$i$pwdLen;$i++) {
$password.=$eligible[rand(0,strlen($eligible))];
  }
  echo(Your new password: $password\n);
?
Bogdan

David T-G wrote:
Shaun --

[No need to post twice...]

...and then Shaun said...
% 
% Hi,

Hi!

% 
% I need to generate a lowercase alphanumeric passwrord thats 8 characters
% long, has anyone got a function that can do this?

This isn't really a regular expression question, since you'd use an
expression to check if a string matched your requirements but not to
generate such a string.
A function should be easy: just loop 8 times over spitting out a random
char between a and z or 0 and 9 (use rand() to generate a number between
0 and 35 and then map that to the char).
% 
% Thanks for your help

Enjoy :-)

HTH  HAND

:-D
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Regular Expression Help: genreate alphanumeric, 8 chars

2003-11-27 Thread David T-G
Bogdan --

...and then Bogdan Stancescu said...
% 
% ...as in...
% 
% ?
%   // Could've been done with ASCII sets, but this way
%   // you can easily tweak the eligible characters.
%   $eligible='abcdefghijklmnopqrstuvwxyz0123456789';
%   $pwdLen=8;
%   $password='';
%   for($i=0;$i$pwdLen;$i++) {
% $password.=$eligible[rand(0,strlen($eligible))];
%   }
%   echo(Your new password: $password\n);
% ?

Looks good to me.  You're too kind; I was going to leave the exercise to
the student to complete :-)


% 
% Bogdan


HTH  HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



pgp0.pgp
Description: PGP signature


Re: [PHP] Regular Expression Help: genreate alphanumeric, 8 chars

2003-11-27 Thread Burhan Khalid
Shaun wrote:

Hi,

I need to generate a lowercase alphanumeric passwrord thats 8 characters
long, has anyone got a function that can do this?
No, but I can write a quick one for you. Can't guarantee the uniqueness 
of the password being generated.

function passgen()
{
   srand((float) microtime() * 1000);
   //Source arrays
   $letters = range('a','z');
   $digits  = range(1,9);
   //Get random items from arrays
   $char = array_rand($letters, 4);
   $num  = array_rand($digits, 4);
   //Combine the two random items into one array
   for ($i = 0; $i 4; ++$i)
   {
 $ran_char[] = $letters[$char[$i]];
 $ran_num[]  = $digits[$num[$i]];
   }
   //build our password
   $password = array_unique(array_merge($ran_char, $ran_num));
   //randomize it
   shuffle($password);
   return join(,$password);
}
echo passgen();

?

--
Burhan Khalid
phplist[at]meidomus[dot]com
http://www.meidomus.com
---
Documentation is like sex: when it is good,
 it is very, very good; and when it is bad,
 it is better than nothing.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Regular Expression Help: genreate alphanumeric, 8 chars

2003-11-27 Thread Adam i Agnieszka Gasiorowski FNORD
David T-G wrote:
 
 Bogdan --
 
 ...and then Bogdan Stancescu said...
 %
 % ...as in...
 %
 % ?
 %   // Could've been done with ASCII sets, but this way
 %   // you can easily tweak the eligible characters.
 %   $eligible='abcdefghijklmnopqrstuvwxyz0123456789';
 %   $pwdLen=8;
 %   $password='';
 %   for($i=0;$i$pwdLen;$i++) {
 % $password.=$eligible[rand(0,strlen($eligible))];
 %   }
 %   echo(Your new password: $password\n);
 % ?
 
 Looks good to me.  You're too kind; I was going to leave the exercise to
 the student to complete :-)

  How about,

 $password = strtolower(substr(md5(uniqid(time())), 0, 7));

  Will get you a unique password consisting of 8 
 rather random lowercase alphanumerics.

-- 
Seks, seksi, seksolatki... news:pl.soc.seks.moderowana
http://hyperreal.info  { iWanToDie }   WiNoNa)   (
http://szatanowskie-ladacznice.0-700.pl  foReVeR(  *  )
Poznaj jej zwiewne ksztaty... http://www.opera.com 007

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php