aveach Posted February 25, 2003 Share Posted February 25, 2003 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 Quote Link to comment Share on other sites More sharing options...
pallevillesen Posted February 28, 2003 Share Posted February 28, 2003 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. Quote Link to comment Share on other sites More sharing options...
benW Posted March 1, 2003 Share Posted March 1, 2003 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.