+ Reply to Thread
Results 1 to 8 of 8

Thread: Random password generation

  1. #1
    Learning Programmer Divya is an unknown quantity at this point
    Join Date
    Apr 2008
    Location
    India
    Posts
    32

    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. #2
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    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?

  3. #3
    Code Warrior BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch's Avatar
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Age
    19
    Posts
    2,223
    Blog Entries
    8

    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?

  4. #4
    Learning Programmer Divya is an unknown quantity at this point
    Join Date
    Apr 2008
    Location
    India
    Posts
    32

    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>

  5. #5
    Code Warrior BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch's Avatar
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Age
    19
    Posts
    2,223
    Blog Entries
    8

    Re: Random password generation

    Have you written any PHP code besides that function?

  6. #6
    Learning Programmer Divya is an unknown quantity at this point
    Join Date
    Apr 2008
    Location
    India
    Posts
    32

    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 10:41 AM. Reason: add code tags (the PHP sheet)

  7. #7
    Learning Programmer Divya is an unknown quantity at this point
    Join Date
    Apr 2008
    Location
    India
    Posts
    32

    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...

  8. #8
    Banned arslan220 is an unknown quantity at this point
    Join Date
    Apr 2009
    Posts
    63

    Re: Random password generation

    thanks this script was really very useful.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Random generation of string, towards goal result
    By Bishop in forum General Programming
    Replies: 4
    Last Post: 03-04-2010, 04:38 AM
  2. Password Program
    By dejongajongjong in forum Pascal/Delphi
    Replies: 7
    Last Post: 01-07-2010, 01:10 PM
  3. Encryption using Random!?
    By TcM in forum Programming Theory
    Replies: 14
    Last Post: 01-07-2008, 10:48 AM
  4. Random Map Generation
    By chax in forum Perl
    Replies: 3
    Last Post: 09-03-2007, 08:58 PM
  5. Forgot Your Password On XP?
    By pranky in forum Tutorials
    Replies: 12
    Last Post: 04-26-2007, 09:08 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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