PDA

View Full Version : "Forgot password" script.



csabi_fl
06-26-2007, 04:49 AM
Hi everybody,
I am looking for a simple "Forgot password" script for my website.
By the way you are more than welcome to check out my site that I built with BlueVoda.
http://www.iqtest4fun.com
Thank you.

navaldesign
06-26-2007, 09:03 AM
A forgot password script needs to

1. Have a user input (usually the username, or user email address)
2. Verify that this username or email address is registered in the databse
3. Email, to the registered email address, the login details.

So the actual coding of this script depends on the structure of your databse table.
As you understand, there is no way that there can be a script that will suit all cases. It has to be made case by case.

csabi_fl
06-26-2007, 06:40 PM
I found a script but it isn't working.
Could you please take a look at it and tell me why it keeps giving me
"no such login in the system. please try again."
even when I use a loginid that is in my database.

<?php
@mysql_pconnect("localhost", "", "") or die("Cannot connect to DB!");
@mysql_select_db("") or die("Cannot select DB!");
$sql="SELECT password,email FROM forms WHERE loginid='$loginid'";
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}
if(mysql_affected_rows()==0){
print "no such login in the system. please try again.";
exit();
}
else {
$row=mysql_fetch_array($r);
$password=$row["password"];
$email=$row["email"];
$subject="your password";
$header="from:ydmmtbz@iqtest4fun.com";
$content="your password is .$password.";
mail($email, $subject, $row, $header);
print "An email containing the password has been sent to you";
}
?>

Watdaflip
06-26-2007, 07:54 PM
That specific script checks for a column called "loginid" from the table "forms" for a value. The script does not collect any data to be checked against the database. (Usually posted data from a form).

The script has 2 check

The first checks if the query is successful
The second checks if a row in the table was found
If it passes both then it will display the information from the row in the table.

Yours is failing in the second check

You need to post the data to the script for it to check the database with

csabi_fl
06-26-2007, 08:21 PM
Thanks.So how would you modify that particular script?

Watdaflip
06-26-2007, 09:27 PM
It would depend on the form that the user enters their login id in to have their information emailed.

Basically, assuming that the "name" attribute of the text field they enter their login id is "loginid", then just add:

$loginid = $_POST['loginid'];

Andwhere before this line:

$sql="SELECT password,email FROM forms WHERE loginid='$loginid'";

navaldesign
06-26-2007, 09:35 PM
1. Create a login form. There the user should type his "loginid" in a fie ld named "loginid". (though usually this is more known as "username rather than "loginid"). Set the form action to be this very script.
Then, add the lines in red in your script:


<?php

$loginid = trim($_POST['loginid']);
@mysql_pconnect("localhost", "user", "password") or die("Cannot connect to DB!");
@mysql_select_db("dbname") or die("Cannot select DB!");
$sql="SELECT password,email FROM forms WHERE loginid='$loginid'";
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}
if(mysql_affected_rows()==0){
print "no such login in the system. please try again.";
exit();
}
else {
$row=mysql_fetch_array($r);
$password=$row["password"];
$email=$row["email"];
$subject="your password";
$header="from:ydmmtbz@iqtest4fun.com";
$content="Your password is $password.";
mail($email, $subject, $content, $header);
print "An email containing the password has been sent to you";
}
?>

navaldesign
06-26-2007, 09:36 PM
Ooops! Sorry Watdaflip. Just had the browser open and didn't see that you had already posted.

csabi_fl
06-27-2007, 05:16 AM
Hi guys,
I can't figure out why I keep getting the following error:

Parse error: syntax error, unexpected '=' in /home/.../public_html/forgot.php on line 28

Any ideas?

Watdaflip
06-27-2007, 02:18 PM
what is line 28 of your script?

csabi_fl
06-27-2007, 02:24 PM
This is the entire script:

<?php
loginid = trim($_POST['loginid']);
@mysql_pconnect("localhost", "", "") or die("Cannot connect to DB!");
@mysql_select_db("") or die("Cannot select DB!");
$sql="SELECT password,email FROM forms WHERE loginid='$loginid'";
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}
if(mysql_affected_rows()==0){
print "no such login in the system. please try again.";
exit();
}
else {
$row =mysql_fetch_array($r);
$password=$row["password"];
$email=$row["email"];
$subject="your password";
$header="from:ydmmtbz@iqtest4fun.com";
$content="your password is .$password.";
mail($email, $subject, $content, $header);
print "An email containing the password has been sent to you";
}
?>

Funny thing is there isn't a line 28 ?!

navaldesign
06-27-2007, 03:34 PM
Did you by any chance paste the the script in a html page ?

csabi_fl
06-27-2007, 03:49 PM
No,it is php I just double-checked again.

navaldesign
06-27-2007, 03:55 PM
It makes no sence. I suggest that you connect with FTP, double click on the "forgot.php" file. Notepad should open with the file content in it. Copy and post here the actual code if it is different from the one you posted.

Or, if you wish, send me (http://www.dbtechnosystems.com/contact.php) your login details, and i will have an inside look.

navaldesign
06-27-2007, 04:21 PM
Hi,
as i thought, you have pasted the script in an empty BV page, which has added some lines of code, that's why the script was givin error in line 28. In fact, there was a $ missing:

$loginid = trim($_POST['loginid']);

Fixed and uploaded on the server.

I also sent you an email but got a message about your mailbox being full.

csabi_fl
06-27-2007, 04:56 PM
Thank you for fixing that.
Now the problem is that I keep getting "no such login in the system. please try again.".I use a loginid that is in my database and still get that.Can you go back inside and see why?
Also you mentioned my mailbox being full.When I go to webmail in my control panel it says it is empty!?What is going on?I might be missing important mail from my members and I don't even know it!

navaldesign
06-27-2007, 05:02 PM
What's the link to the form that sends to the forgot.php ?

csabi_fl
06-27-2007, 06:05 PM
login.php

navaldesign
06-27-2007, 06:15 PM
Change the Enctype of your login.php form in "multipart / form data", save and republish

csabi_fl
06-27-2007, 06:32 PM
GREAT.It is working now.
By the way what do you say about my mailbox being full when it is in fact empty?

csabi_fl
06-27-2007, 07:19 PM
I think I got it.
The neomail trash folder filled up my quota.I didn't bother to check the trash folder only the new mail that's why I missed it the first time.
For everybody out there if this ever happens to you then just raise the quota and your mailbox will never get full even if you forget to check it for a while.
Navaldesign,thanks for all your help .

navaldesign
06-27-2007, 08:16 PM
Glad you sorted it. By the way, i did raise your webmail quota to 100 MB