Go Back   CodeCall Programming Forum > Web Development Forum > PHP Forum
Register Blogs Search Today's Posts Mark Forums Read

PHP Forum Use this forum to discuss all aspects of PHP Development. PHP is a server-side, cross-platform, HTML embedded scripting language that lets you create dynamic web pages.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-16-2009, 07:21 AM
Learning Programmer
 
Join Date: Apr 2008
Location: India
Posts: 32
Divya is an unknown quantity at this point
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..

PHP 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????
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-16-2009, 08:00 AM
Jordan's Avatar
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 24,556
Jordan is a name known to allJordan is a name known to allJordan is a name known to allJordan is a name known to allJordan is a name known to allJordan is a name known to all
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan Send a message via Yahoo to Jordan
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-16-2009, 10:07 AM
BlaineSch's Avatar
Code Warrior
 
Join Date: Apr 2009
Location: Trapped in my own little world.
Age: 19
Posts: 2,169
BlaineSch is a glorious beacon of lightBlaineSch is a glorious beacon of lightBlaineSch is a glorious beacon of lightBlaineSch is a glorious beacon of lightBlaineSch is a glorious beacon of lightBlaineSch is a glorious beacon of light
Send a message via MSN to BlaineSch
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-16-2009, 11:32 PM
Learning Programmer
 
Join Date: Apr 2008
Location: India
Posts: 32
Divya is an unknown quantity at this point
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>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 06-16-2009, 11:34 PM
BlaineSch's Avatar
Code Warrior
 
Join Date: Apr 2009
Location: Trapped in my own little world.
Age: 19
Posts: 2,169
BlaineSch is a glorious beacon of lightBlaineSch is a glorious beacon of lightBlaineSch is a glorious beacon of lightBlaineSch is a glorious beacon of lightBlaineSch is a glorious beacon of lightBlaineSch is a glorious beacon of light
Send a message via MSN to BlaineSch
Re: Random password generation

Have you written any PHP code besides that function?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 06-17-2009, 12:26 AM
Learning Programmer
 
Join Date: Apr 2008
Location: India
Posts: 32
Divya is an unknown quantity at this point
Re: Random password generation

i have written the insert query as follows:
PHP 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 11:41 AM.. Reason: add code tags (the PHP sheet)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 06-17-2009, 01:43 AM
Learning Programmer
 
Join Date: Apr 2008
Location: India
Posts: 32
Divya is an unknown quantity at this point
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...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 07-03-2009, 07:42 AM
Banned
 
Join Date: Apr 2009
Posts: 63
arslan220 is an unknown quantity at this point
Re: Random password generation

thanks this script was really very useful.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Password Program dejongajongjong Pascal/Delphi 7 01-07-2010 02:10 PM
Random generation of string, towards goal result Bishop General Programming 3 11-09-2008 07:39 PM
Encryption using Random!? TcM Programming Theory 14 01-07-2008 11:48 AM
Random Map Generation chax Perl 3 09-03-2007 09:58 PM
Forgot Your Password On XP? pranky Tutorials 12 04-26-2007 10:08 AM


All times are GMT -5. The time now is 08:16 AM.


vBulletin v3.8.0 ©2010, Jelsoft Enterprises Ltd.


no new posts

LinkBacks Enabled by vBSEO 3.1.0