Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: password generator code

  1. #1
    Join Date
    Dec 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default password generator code

    1) CODE TITLE: pissedandhappy password gen

    2) AUTHOR NAME/NOTES: Peter

    3) DESCRIPTION: this code complicated java code produces a number of random passwords, i currently can not find a good use for it but i think that it will be good for some sort of user database. Please tell me if you do use this code by emailing me at micklep@hotmail.com

    4) URL TO CODE: http://www.stuff.pissedandhappy.co.uk/password-gen.txt

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,156
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    It's javascript, so implementation in a database would be impossible, without recoding to php, asp, etc.

    I'm confused by the various scripts... why is it setup in so many seperate <script></script> elements? Seems like needless extra stuff to me.

    Really, you've just kinda randomly assigned things, but you could create a real random script by using the ordinal values for characters (0-9,a-z,A-Z, and symbols, etc. if you wanted) and choosing one at random.

    Here's the PHP--
    PHP Code:
    <?php
    $len 
    8//set pass length //in this case, 8
    for ($n=0;$n<$len;$n++) { //loop starting at 0, while less than len value
    $ord rand(1,62); //10num+26LET+26let //add more if you want
    if ($ord <= 10) {$ord += 47;} //numbers
    else if ($ord <= 36) {$ord += 54;} //LETTERS
    else { $ord += 60; } //letters
    //include other sets of chars if you want
    $pass .= chr($ord); //add char to existing password
    }
    echo 
    $pass//output password
    ?>
    Untested, but should work just fine.

    If we were to compare the outputs, they would differ in complexity and randomness. Since you are using a much more limited set of characters, the inclusive code above would generate many more possible outcomes. Yours can work too, but this just has more possibilities.
    I don't do JS, but I'm sure there's a way to do this as well.
    You could just output as html, and use &#nn; for example.


    EDIT: Consider this a submission if it seems worthy.


    EDIT AGAIN: Ok, code fixed above...
    Last edited by djr33; 12-19-2006 at 09:11 AM.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,156
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    http://ci-pro.com/misc/phptest/passgen.php
    That's a test page.

    I had an error in the script earlier, but it's fixed now.
    I was adding the full value for each set, like 64 for capital letters, but then realized that to be wrong since that set of random values starts at 10, so needed to subtract that first. For the next, subtract 10+26, so not 96, but 60.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Great drj33!!! 10/10

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,156
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Hmm.... here's a more logical way to look at the code:
    PHP Code:
    <?php
    $len 
    8//set pass length //in this case, 8
    for ($n=0;$n<$len;$n++) { //loop starting at 0, while less than len value
    $ord rand(1,62); //10num+26LET+26let //add more if you want
    if ($ord <= 10) {
       
    $ord += 47//numbers
       
    }
    else {
       
    $ord -= 10;
       if (
    $ord <= 26) {
          
    $ord += 64//LETTERS
          
    }
       else {
          
    $ord -= 26
          
    $ord += 96//letters
          
    }
       }
    //include other sets of chars if you want
    $pass .= chr($ord); //add char to existing password
    }
    echo 
    $pass//output password
    ?>
    The math was weird, and it confused me, so it's bound to confuse others, considering I wrote the script in the first place.


    Hmm.... I might write that into an array/foreach function so you an specify character sets within the array (which would, interestingly enough, be a 3D array )
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Dec 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    in answer to your second post, the reason i did it in so many seperate script is because i was brand new to javascript.

    Thanks to you i now know that i can put them all together in 1 set of code. I have produced another script that i think is rather fun:

    DONT LOOK IF EASILY OFFENDED:

    http://www.stuff.pissedandhappy.co.uk/insult.html

    Tell me what you think, i added some html to spruce it up a bit but it seems to really affect loading time

    Cheers

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Haha, er, interesting
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,156
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Hmmmm.... different.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Jan 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    my variant is
    PHP Code:
    <?
        
    function exPassGen$passlen )
        {
            
    $lets = array(
                            
    => range('a''z'),
                            
    => range('A''Z'),
                            
    => range('0''9'),
                            
    => array('~''!''#''@''$''^'':''('')''-''_''+''='),
                          );
            
    $ret '';
            
             for( 
    $i 0$i $passlen$i++ )
             {
                
    $lrnd rand(0count($lets)-);
                
    $ret .= $lets[$lrnd][ rand(0,count($lets[$lrnd])-1) ];
             }
             
         return 
    $ret;
        }
        
        echo 
    exPassGen10 )."<br/>"
        echo 
    exPassGen);
    ?>
    Last edited by exed; 01-06-2007 at 02:58 PM. Reason: fix 1

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,156
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Hmm.... perhaps. But most of those symbols aren't valid as passwords, if you actually want to use that. You could use up to 255 characters, but many wouldn't work. Depends on the exact system, though.

    Also, using the ascii codes really makes sense in this case, since it can be changed fairly easily. But doing it like that could work as well.

    Do you have a test page?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •