Random Password PHP code help req.. only gettinh 3 letters?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • techcs

    Random Password PHP code help req.. only gettinh 3 letters?

    Hi,

    Wondering if anyine can help with the membership PHP script I lifted
    from a tutorial. I'm new to PHP and have this system up and running but
    my password only come out at three letters and sometime have a space in
    them?? Anyway this is the code:

    function makeRandomPassw ord($len = 8,$upper = 1,$number = 1) {
    $salt = "abcdefghijklmn opqrstuvwxyz";
    $uppercase = "ABCDEFGHIJKLMN OPQRSTUVWXYZ";
    $numbers = "1234567890 ";
    if ($upper) $salt .= $uppercase;
    if ($number) $salt .= $numbers;

    srand((double)m icrotime()*1000 000);
    $i = 0;
    while ($i <= $len) {
    $num = rand() % strlen($salt);
    $tmp = substr($salt, $num, 1);
    $pass = $num . $tmp;
    $i++;
    };
    return $pass;
    };

    $random_passwor d = makeRandomPassw ord();

    $db_password = md5($random_pas sword);

    Any ideas.. I need maybe 5 letters with no spaces...

    Thanks
    Col

  • Alvaro G. Vicario

    #2
    Re: Random Password PHP code help req.. only gettinh 3 letters?

    *** techcs escribió/wrote (14 Sep 2006 12:58:34 -0700):
    Wondering if anyine can help with the membership PHP script I lifted
    from a tutorial. I'm new to PHP and have this system up and running but
    my password only come out at three letters and sometime have a space in
    them??

    I'd replace this part...
    $i = 0;
    while ($i <= $len) {
    $num = rand() % strlen($salt);
    $tmp = substr($salt, $num, 1);
    $pass = $num . $tmp;
    $i++;
    };
    .... with this code:

    $pass='';
    $max=strlen($sa lt)-1;
    for($i=0; $i<$len); $i++){
    $pass.=$salt{mt _rand(0, $max)};
    }


    --
    -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
    ++ Mi sitio sobre programación web: http://bits.demogracia.com
    +- Mi web de humor con rayos UVA: http://www.demogracia.com
    --

    Comment

    • techcs

      #3
      Re: Random Password PHP code help req.. only gettinh 3 letters?

      Hi, thanks for that but I get a parse error with that code, maybe I
      have to change some of the other bit to match, will have another
      look...

      Cheers
      Col
      Alvaro G. Vicario wrote:
      *** techcs escribió/wrote (14 Sep 2006 12:58:34 -0700):
      Wondering if anyine can help with the membership PHP script I lifted
      from a tutorial. I'm new to PHP and have this system up and running but
      my password only come out at three letters and sometime have a space in
      them??
      >
      >
      I'd replace this part...
      >
      $i = 0;
      while ($i <= $len) {
      $num = rand() % strlen($salt);
      $tmp = substr($salt, $num, 1);
      $pass = $num . $tmp;
      $i++;
      };
      >
      ... with this code:
      >
      $pass='';
      $max=strlen($sa lt)-1;
      for($i=0; $i<$len); $i++){
      $pass.=$salt{mt _rand(0, $max)};
      }
      >
      >
      --
      -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
      ++ Mi sitio sobre programación web: http://bits.demogracia.com
      +- Mi web de humor con rayos UVA: http://www.demogracia.com
      --

      Comment

      • Alvaro G. Vicario

        #4
        Re: Random Password PHP code help req.. only gettinh 3 letters?

        *** techcs escribió/wrote (14 Sep 2006 14:44:16 -0700):
        Hi, thanks for that but I get a parse error with that code, maybe I
        have to change some of the other bit to match, will have another
        look...
        I didn't test the code. Just remove the unexpected ')'.

        >$pass='';
        >$max=strlen($s alt)-1;
        >for($i=0; $i<$len); $i++){
        > $pass.=$salt{mt _rand(0, $max)};
        >}
        --
        -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
        ++ Mi sitio sobre programación web: http://bits.demogracia.com
        +- Mi web de humor con rayos UVA: http://www.demogracia.com
        --

        Comment

        • techcs

          #5
          Re: Random Password PHP code help req.. only gettinh 3 letters?

          Thanks Alvaro,

          That works great.. Much appreciated..

          Col
          *** techcs escribió/wrote (14 Sep 2006 14:44:16 -0700):
          Hi, thanks for that but I get a parse error with that code, maybe I
          have to change some of the other bit to match, will have another
          look...
          >
          I didn't test the code. Just remove the unexpected ')'.
          >
          >
          $pass='';
          $max=strlen($sa lt)-1;
          for($i=0; $i<$len); $i++){
          $pass.=$salt{mt _rand(0, $max)};
          }
          >
          --
          -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
          ++ Mi sitio sobre programación web: http://bits.demogracia.com
          +- Mi web de humor con rayos UVA: http://www.demogracia.com
          --

          Comment

          Working...