Jump to content

Archived

This topic is now archived and is closed to further replies.

aveach

Rand() ?

Recommended Posts

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.