SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2004
    Location
    Fort Lauderdale
    Posts
    522
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Password generator help

    I would like to create a password generator that creates a password from an array of words and at the end appends 4 digit number. For example:

    $words = array(dog, cat, mirror, outside, love, mother, brother, potatoe);

    I would like to create a password generator that will randomly pick one of the words from the array and at the end of teh word append a 4 digit number.

    How can I implement that?

    Thanks

  2. #2
    SitePoint Guru
    Join Date
    Jul 2004
    Location
    Raleigh, NC
    Posts
    783
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $words = array(dogcatmirroroutsidelovemotherbrotherpotatoe);
    $rand_word array_rand($words1);
    $rand_num_short rand(09999);
    $rand_num_long str_pad($rand_num_short4'0'STR_PAD_LEFT);
    $password $rand_val[0] . $rand_num_long

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2004
    Location
    Fort Lauderdale
    Posts
    522
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do echo $password and it only shows the 4 digits...no words...
    some mistake there....

  4. #4
    Passionate Web Developer Egyptechno's Avatar
    Join Date
    Jan 2004
    Location
    Dubai
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this :
    PHP Code:
    $a=array("a","b","c","d");
    explode (',',$a);
    $num=rand(0,count($a));
    echo 
    $a[$num];

    $digit=array(1,2,3,4,5,6,7,8,9);
    for(
    $i=0;$i<=3;$i++){
    $dd=rand(0,count($digit));
    echo 
    $digit[$dd];

    the result will be : (example)
    a9665
    c2112
    a4456

    regards,

  5. #5
    SitePoint Evangelist
    Join Date
    Mar 2004
    Location
    Fort Lauderdale
    Posts
    522
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I fixed it...it works great..minor mistake you made:

    $words = array(dog, cat, mirror, outside, love, mother, brother, potatoe);
    $rand_value = array_rand($words, 1);
    $rand_num_short = rand(0, 9999);
    $rand_num_long = str_pad($rand_num_short, 4, '0', STR_PAD_LEFT);
    $password = $words[$rand_value] . $rand_num_long;

  6. #6
    SitePoint Evangelist
    Join Date
    Mar 2004
    Location
    Fort Lauderdale
    Posts
    522
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $words = array(dog, cat, mirror, outside, love, mother, brother, potatoe);
    $rand_value = array_rand($words, 1);
    $rand_num_short = rand(0, 9999);
    $rand_num_long = str_pad($rand_num_short, 4, '0', STR_PAD_LEFT);
    $password = $words[$rand_value] . $rand_num_long;

    do echo $password and its VERY NICE

  7. #7
    SitePoint Guru
    Join Date
    Jul 2004
    Location
    Raleigh, NC
    Posts
    783
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by photo312
    $words = array(dog, cat, mirror, outside, love, mother, brother, potatoe);
    $rand_value = array_rand($words, 1);
    $rand_num_short = rand(0, 9999);
    $rand_num_long = str_pad($rand_num_short, 4, '0', STR_PAD_LEFT);
    $password = $words[$rand_value] . $rand_num_long;

    do echo $password and its VERY NICE
    glad it worked. sorry about the type-o

  8. #8
    SitePoint Addict
    Join Date
    Apr 2002
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by photo312
    I would like to create a password generator that creates a password from an array of words and at the end appends 4 digit number. For example:

    $words = array(dog, cat, mirror, outside, love, mother, brother, potatoe);

    I would like to create a password generator that will randomly pick one of the words from the array and at the end of teh word append a 4 digit number.

    How can I implement that?
    Although this is not what you are asking, mind me for an opinion on a different approach.

    It seems that you are trying to generate user passwords that are easy to remember and eventually send them to the users by e-mail.

    If that is the case, that approach has a couple of problems. Users tend to forget passwords that they did not choose and passwords sent by e-mail are considered a security hole (anobody that has access to messages sent to the user can take advantage of his privileges).

    Instead, I suggest sending the users an e-mail with a special URL that has a random authentication key that can be verified against a private key stored in his account records to let the user choose his initial password. This way you let the user choose a password that he is less likely to forget and the password is never shown in an e-mail.
    Manuel Lemos

    Metastorage - Data object relational mapping layer generator
    PHP Classes - Free ready to use OOP components in PHP

  9. #9
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    If you are trying to create pronounceable passwords, have a look at PEAR::Text_Password

  10. #10
    SitePoint Evangelist
    Join Date
    Mar 2004
    Location
    Fort Lauderdale
    Posts
    522
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am trying to get random passwords unlike: 'usi893jisjkg3' which some websites generate. I want users to login using the password that I create and then change it.

    Its not about making it too easy. Its about making it simple.


  11. #11
    SitePoint Addict
    Join Date
    Apr 2002
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by photo312
    I am trying to get random passwords unlike: 'usi893jisjkg3' which some websites generate. I want users to login using the password that I create and then change it.

    Its not about making it too easy. Its about making it simple.
    What I am trying to tell you is that in my experience that will give you more work than you could care if you get many users.

    What happens is that not only the users will not remember passwords that did not defined, but also most of them will not change it. They will just copy and paste the password once and remove the message.

    When they get back to the site after a while, they will have forgotton the password and will ask for a new password. The problem for you is that many of those will not even remember the right user name that they have choosen and will either mail you for help or give up your site.
    Manuel Lemos

    Metastorage - Data object relational mapping layer generator
    PHP Classes - Free ready to use OOP components in PHP

  12. #12
    SitePoint Evangelist
    Join Date
    Mar 2004
    Location
    Fort Lauderdale
    Posts
    522
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Allright,

    So what you recommend is to have a link.
    User will click on that link and activate the account?
    What about the password then?

    Paul

  13. #13
    SitePoint Addict
    Join Date
    Apr 2002
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by photo312
    So what you recommend is to have a link.
    User will click on that link and activate the account?
    What about the password then?
    The password and a reminder phrase is chosen by the user in the page indicated by the link. Until the user goes to that page, the account is not activated.

    The same type message of message and password resetting procedure can be used when the user forgets his password or user name.

    Because some users are impatient, make the link be valid only for 24 hours. Until it expires, do not let the user request a new password setting/reminder message.
    Manuel Lemos

    Metastorage - Data object relational mapping layer generator
    PHP Classes - Free ready to use OOP components in PHP

  14. #14
    SitePoint Evangelist
    Join Date
    Mar 2004
    Location
    Fort Lauderdale
    Posts
    522
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do you know of an example that I can see of this type of funcionality?

    Paul

  15. #15
    SitePoint Addict
    Join Date
    Apr 2002
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by photo312
    do you know of an example that I can see of this type of funcionality?
    Yes, I have implemented it in the PHP Classes repository site. Initially it was more like what you had in mind, but because of the problems that were consuming too much of my time providing user support, I had to evolve it to make it work like it is today.
    Manuel Lemos

    Metastorage - Data object relational mapping layer generator
    PHP Classes - Free ready to use OOP components in PHP


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
  •