Closed Thread
Results 1 to 8 of 8

Thread: Random password generation

  1. #1
    Divya is offline Learning Programmer
    Join Date
    Apr 2008
    Location
    India
    Posts
    32
    Rep Power
    0

    Random password generation

    I want to generate password randomly and send to mysql database using PHP..i have got the following function for generating password but doesn't know how to incorporate in my registration form and where to call that function and update password field in database..please help me..

    Code:
    function generatePassword $length ) {
        
    // start with a blank password
        
    $password “”;

        
    // define possible characters
        
    $possible “0123456789abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ!@#$%^&*”;

        // set up a counter
        
    $i 0;

        
    // add random characters to $password until $length is reached
        
    while ($i $length) {
        
    // pick a random character from the possible ones
        
    $char substr($possiblemt_rand(0strlen($possible)-1), 1);

        
    // we don’t want this character if it’s already in the password
        
    if (!strstr($password$char)) {
        
    $password .= $char;
        
    $i++;
        }
        }
        
    // done!
        
    return $password;
        } 
    where should i call this function generatePassword????

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Jordan Guest

    Re: Random password generation

    In order for us to answer we will need to know a bit more about your registration form. Do you allow your user to enter the password or do you always want a generated password?

  4. #3
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Posts
    2,487
    Rep Power
    33

    Re: Random password generation

    If you are always generating a password you should just have to call that function.

    Can you show us the registration page?

  5. #4
    Divya is offline Learning Programmer
    Join Date
    Apr 2008
    Location
    India
    Posts
    32
    Rep Power
    0

    Re: Random password generation

    I am not allowing the user to enter the password.i want to generate it and send it to user's email.my registration form is:
    Code:
    <form name="account" method="post">
    <div><h2>User Account</h2></div>
    <fieldset><legend><b>Account Information</b></legend>
    <div>Username<span style="color:#FF0000;">*</span></div>
    <div><input type="text" name="un" id="un" style="width:300px;" /></div>
    <div style="font-size:11px;">Spaces are allowed; punctuation is not allowed except for periods, hyphens, and underscores.</div>
    <div>E-mail Address<span style="color:#FF0000;">*</span></div>
    <div><input type="text" name="email" id="email" style="width:300px;" /></div>
    <div style="font-size:11px;">A valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.</div>
    </fieldset>
    
    <fieldset><legend><b>Personal Information</b></legend>
    <div>First Name<span style="color:#FF0000;">*</span></div>
    <div><input type="text" name="fn" id="fn" style="width:300px;"/></div>
    <div>Last Name<span style="color:#FF0000;">*</span></div>
    <div><input type="text" name="ln" id="ln" style="width:300px;" /></div>
    <div style="font-size:11px;">The content of this field is kept private and will not be shown publicly.</div>
    <div>Company Name</div>
    <div><input type="text" name="cn" id="cn" style="width:300px;"/></div>
    <div>Street Address<span style="color:#FF0000;">*</span></div>
    <div><input type="text" name="add" id="add" style="width:300px;" /></div>
    <div style="font-size:11px;">The content of this field is kept private and will not be shown publicly.</div>
    <div>City<span style="color:#FF0000;">*</span></div>
    <div><input type="text" name="cty" id="cty" style="width:300px;" /></div>
    <div>State<span style="color:#FF0000;">*</span></div>
    <div><input type="text" name="state" id="state" style="width:300px;" /></div>
    <div>Postal Code<span style="color:#FF0000;">*</span></div>
    <div><input type="text" name="pin" id="pin" style="width:300px;" /></div>
    <div style="font-size:11px;">The content of this field is kept private and will not be shown publicly.</div>
    <div>Phone Number<span style="color:#FF0000;">*</span></div>
    <div><input type="text" name="phone" id="phone" style="width:300px;" /></div>
    <div style="font-size:11px;">The content of this field is kept private and will not be shown publicly.</div>
    </fieldset>
    <div><input type="submit" name="submit" id="submit" value="Create New Account" /></div>
    </form>

  6. #5
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Posts
    2,487
    Rep Power
    33

    Re: Random password generation

    Have you written any PHP code besides that function?

  7. #6
    Divya is offline Learning Programmer
    Join Date
    Apr 2008
    Location
    India
    Posts
    32
    Rep Power
    0

    Re: Random password generation

    i have written the insert query as follows:
    Code:
    if(isset($_POST['submit']))
    {
        
    $insert=mysql_query("INSERT INTO dress_user(username, email, firstname, lastname, company, address, city, 
        state, pin, phone, password)VALUES('$_POST[un]',    
                                            '$_POST[email]',
                                            '$_POST[fn]',    
                                            '$_POST[ln]',
                                            '$_POST[cn]',
                                            '$_POST[add]', 
                                            '$_POST[cty]', 
                                            '$_POST[state]',
                                            '$_POST[pin]',    
                                            '$_POST[phone]',
                                            '     ')"
    ) or die("Query failed : " mysql_error());


    What should i insert against pw field and where should i write and call the generate password function..??
    Last edited by WingedPanther; 06-17-2009 at 08:41 AM. Reason: add code tags (the PHP sheet)

  8. #7
    Divya is offline Learning Programmer
    Join Date
    Apr 2008
    Location
    India
    Posts
    32
    Rep Power
    0

    Re: Random password generation

    hey thanks for all ur efforts...i have written that function in other php file and included it in the current registration file as follows:

    $pw=generatePassword(8);

    and inserted $pw in against the password field...

  9. #8
    arslan220 Guest

    Re: Random password generation

    thanks this script was really very useful.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Program for Image Processing & Random Sentence Generation
    By chax in forum General Programming
    Replies: 5
    Last Post: 10-08-2011, 01:30 PM
  2. Using a random function to generate another random funtion
    By Roger in forum General Programming
    Replies: 11
    Last Post: 08-23-2010, 08:07 AM
  3. Random generation of string, towards goal result
    By Bishop in forum General Programming
    Replies: 4
    Last Post: 03-04-2010, 02:38 AM
  4. Random Password Generator
    By Sauce in forum Visual Basic Programming
    Replies: 13
    Last Post: 06-25-2009, 02:57 PM
  5. Random Map Generation
    By chax in forum Perl
    Replies: 3
    Last Post: 09-03-2007, 06:58 PM

Tags for this Thread

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