[PHP] [REL] Password Generator Script

Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    Apprentice TheTrickyPart is offline
    MemberRank
    Nov 2011 Join Date
    17Posts

    Re: [PHP] [REL] Password Generator Script

    It's beatiful xD thanks.

  2. #17
    Omega Ron is offline
    MemberRank
    Apr 2005 Join Date
    Location
    8,990Posts

    Re: [PHP] [REL] Password Generator Script

    Quote Originally Posted by iAkira View Post
    why not just use booleans instead of 1 or 0
    A lot of people (including myself) will use 1/0 instead of True/False just because its faster, especially when writing small scripts where it doesn't matter if you use a boolean or 1/0.

  3. #18
    The Gamma..? EliteGM is offline
    MemberRank
    Jul 2006 Join Date
    NandolandLocation
    4,078Posts

    Re: [PHP] [REL] Password Generator Script

    Also doing (bool)1/0 will make true/false iirc

  4. #19
    :-) s-p-n is offline
    DeveloperRank
    Jun 2007 Join Date
    Next DoorLocation
    2,098Posts

    Re: [PHP] [REL] Password Generator Script

    Quote Originally Posted by Ron View Post
    A lot of people (including myself) will use 1/0 instead of True/False just because its faster, especially when writing small scripts where it doesn't matter if you use a boolean or 1/0.
    Okay, integers are not "faster". Integers can have a positive or negative "2147483647" on 32-bit systems, and up to "9223372036854775807" on 64-bit systems. That's a lot of bytes.

    Booleans are 0 or 1 on all systems.

    Integers in PHP take much more computation as PHP has a lot of features for math- it supports scientific notation, and changes the results to the more user-friendly whenever possible. You can also do math on several different base-numbers as PHP integers. So integers are in no way "faster" than boolean.

    When you use any type in a conditional statement, it is automagicly converted to boolean anyway. As PHP versions change, the way that "magic" works can also change, making this style of programming not only a waste of resources, but also some-what unreliable in later version releases.


    Let me correct you. The reason you use integers instead of boolean is because you're either lazy or stupid.


    Don't use a chainsaw to do what can be done with scissors.

  5. #20
    may web.very maple.pls. iAkira is offline
    MemberRank
    Aug 2009 Join Date
    somewhere..Location
    2,378Posts

    Re: [PHP] [REL] Password Generator Script

    Well I optimized(??) it a bit more using booleans
    PHP Code:
    <?php
    /*
        $l :: the length of your password
        $s :: (1 to include symbols) (0 for no symbols)
        $n :: (1 to include numbers) (0 for no numbers)
        $uc :: (1 to include no upper-case letters) (0 for no upper-case letters)
        $lc :: (1 to include no lower-case letters) (0 for no lower-case letters)
    */

    function GeneratePassword$l$s$n$uc$lc) {
       
    $d = array('''''''''''');
       foreach(
    range('A''z') as $i) {
             if(
    mb_strlen($d[2]) != 26$d[2] .= $i//uppercase letters
             
    else if(mb_strlen($d[0]) != 6$d[0] .= $i//symbols
             
    else  break; 
       }
       foreach(
    range('0''9') as $i$d[1] .= $i//numbers
       
    foreach (range('!''/') as $i$d[0] .= $i//more symbols
       
    $d[3] .= strtolower($d[2]); //lowercase letters

       
    $arg func_get_args();
       for (
    $i 1$i 5$i++) if ($arg[$i]) $d[4] .= $d[$i-1];
       if ( !
    $s && !$n && !$uc && !$lc $d[4] = $d[0].$d[2].$d[3];
       for(
    $p 1$p <= $l$p++) $d[5] .= substr($d[4], mt_rand($pstrlen($d[4])), 1);
      return 
    htmlentities($d[5]);
    }

    echo 
    GeneratePassword(5falsefalsetruetrue);
    ?>

  6. #21
    hi i'm robbie Roper is offline
    MemberRank
    Oct 2008 Join Date
    /home/roperLocation
    2,283Posts

    Re: [PHP] [REL] Password Generator Script

    Fantastic, this kinda thing would be good for on a registration page, there could be an ajax litebox which pops up if you click "Generate password" and then allows you to use it. Just an idea ;)

  7. #22
    Web Developer Markshall is offline
    MemberRank
    Oct 2009 Join Date
    EnglandLocation
    628Posts

    Re: [PHP] [REL] Password Generator Script

    Quote Originally Posted by Roper View Post
    Fantastic, this kinda thing would be good for on a registration page, there could be an ajax litebox which pops up if you click "Generate password" and then allows you to use it. Just an idea ;)
    Yeah I'mma use it on mUserSystem! ;P



Page 2 of 2 FirstFirst 12

Advertisement