Jump to content


Photo

Rand() ?


  • Please log in to reply
2 replies to this topic

#1 aveach

aveach
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 25 February 2003 - 04:12 AM

Hi,
I am trying to insert random usernames and passwords into my database.
When i just use rand() it generates a number the length of the field between 0 and 1. my fields are set to 15 chars so i end up with something like \"0.1789632597412\". Are there arguments that go with this function that would let me generate a 10 char string made up of random letters and numbers like \"ad4er888af\"? Thanks

#2 pallevillesen

pallevillesen
  • Members
  • PipPipPip
  • Advanced Member
  • 135 posts
  • LocationDenmark

Posted 28 February 2003 - 09:38 AM

Whats wrong with a number as username?

(i.e. chop off the 0. from the beginning of strand, and keep 15 characters...)

Otherwise you\'ll have to make a small function that\'ll return a number of random characters and call that... It\'ll require 15 calls to the rand function...

Maybe you _could_ do a trick by encoding the random number to a password by using crypt($string) - I\'m not absolutely sure what it returns - maybe just numbers as well... try it...

P.
Palle Villesen, www.birc.dk [br]Bioinformatics Research Center

#3 benW

benW
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationWaukesha WI

Posted 01 March 2003 - 01:35 AM

I would use something like:
[php:1:97f8fee0cf]<?php
$unique = microtime();
$randstr = md5($unique);
$randstr = substr(\"$randstr\", 0,10);
print \"\".$randstr.\"<br />\";

$randpass = md5($randstr);
$randpass = substr(\"$randpass\", 0,10);
print $randpass;
?>[/php:1:97f8fee0cf]


<?php str_replace("ASP", "PHP", $str); ?>




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users