Jump to content

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

Link to comment
https://forums.phpfreaks.com/topic/180-rand/
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.

Link to comment
https://forums.phpfreaks.com/topic/180-rand/#findComment-546
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]

Link to comment
https://forums.phpfreaks.com/topic/180-rand/#findComment-553
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.