View Full Version : Forgot password?
Trusten
07-27-2002, 07:05 AM
I need a script that will allow me to make a form that will compare the information on the site, to the information given in a form, then send an email to someone if the data matches.
If someone could point me into that direction, that way, when someone loses their pwd, they can click "forgot your password?" and get a chance to head that way.
I hope this works for you.
<?php
if($go == "1")
{
mysql_connect("host","username","password");
mysql_select_db(databaseName);
$sql = @mysql_query("SELECT * FROM table WHERE username='$name' && email='$email' ");
if(!$sql)
{
echo "The user name and email do not match.";
exit;
}
$query = mysql_query($sql);
$fPass = mysql_fetch_array($query);
mail($email, "Your Password", "User Name: ". $fPass[username] ."\nPassword: ". $fPass[password]);
echo "Your Password has been sent to ". $email .".";
}
?>
<form action="<?= $PHP_SELF ?>" method="post">
Name: <input type="text" name="name" size="24" border="0"><br>
E-mail: <input type="text" name="email" size="24" border="0"><br>
<input type="hidden" name="go" value="1" border="0"><input type="submit" name="submitButtonName" border="0">
</form>
Trusten
07-27-2002, 01:58 PM
thank you.
Oh, forgot to mention, it also uses md5 or whatever, that password thingy that encryps.
could you compensate for that too?
Trusten
07-27-2002, 02:38 PM
oh k. that doesn't look too good. it keeps telling me that the user name and email doesn't match. but i got them to match now. with an error though
in my tables, the user name is in table userid, so i changed that 'username' part, to 'userid'.
how about this also, a script that would use secret questions and secret hints. like they type in their user name and then they are prompted with the question, and if they answer it right, then the password gets sent to them via email.
either way,
Warning: Supplied argument is not a valid MySQL result resource on line 54
that's the new error.
line 54 would be....
$fPass = mysql_fetch_array($query);
because i changed username to userid.
see?
mail($email, "Your Password", "User Name: ". $fPass[userid] ."\nPassword: ". $fPass[password]);
echo "Your Password has been sent to ". $email .".";
also, when it sends me the 'your password', it's a blank email, and it says it's been sent by 'Apache', and it's giving the email address of my main host.
Cloudski
07-27-2002, 03:16 PM
Well, to change the from you would put:
mail($email, "Your Password", "User Name: ". $fPass[userid] ."\nPassword: ". $fPass[password], "FROM: You@yourserver.com");
echo "Your Password has been sent to ". $email .".";
Or I think thats the way it works.. I don't remember right off hand.... :(
Tell me if that works out :thumbsup:
Trusten
07-27-2002, 03:22 PM
thanks cloud, that worked.
now for the fact that it keeps sending me a blank email, and giving me that error.
Cloudski
07-27-2002, 03:30 PM
Well, uh... for the blank E-mail, try this:
mail("$email","Your Password","User Name: $fPass[userid] \n Pasword: $fPass[password]", "From: $from ");
I, unfortunatly, do not know enough about MySQL to help with the error... :(
Anyways,
Good luck! :thumbsup:
Trusten
07-27-2002, 03:31 PM
well it's not a blank email.
it says
username:
password
and that's ALL. it's like totally blank.
:(
Cloudski
07-27-2002, 03:33 PM
Oh, well then it is because your not getting the data... that's what the error is doing... Um.. so your old way may have been better?
*sigh* I wish I knew MySQL... :(
Trusten
07-27-2002, 03:46 PM
no, no, yours works. before i was getting that same email, but it was coming from my host. now i'm getting it from me, yeah, but it's still the same.
i don't know why it's not communicating with the data.
Cloudski
07-27-2002, 04:30 PM
Before you read on, try this:
mail($email, "Your Password", "User Name: ". $fPass["userid"] ."\nPassword: ". $fPass["password"], "FROM: You@yourserver.com");
echo "Your Password has been sent to ". $email .".";
Now IF THAT DOESN'T WORK, try this:
Instead of:
$sql = @mysql_query("SELECT * FROM table WHERE username='$name' && email='$email' ");
if(!$sql)
{
echo "The user name and email do not match.";
exit;
}
$query = mysql_query($sql);
$fPass = mysql_fetch_array($query);
Use this:
$sql = @mysql_query("SELECT * FROM table WHERE username='$name' && email='$email' ");
if(!$sql)
{
echo "The user name and email do not match.";
exit;
}
$myUser = mysql_query(SELECT userid FROM table WHERE userid='$name')
if(!myUser) {
echo("<P>Error performing query: " . mysql_error() . "</P>");
exit();
}
$myPass = mysql_query(SELECT password FROM table WHERE userid='$name')
if(!myPass) {
echo("<P>Error performing query: " . mysql_error() . "</P>");
exit();
}
$fpass1 = mysql_fetch_array($myUser)
$fpass2 = mysql_fetch_array($myPass)
Now, for the e-mail,
mail($email, "Your Password", "User Name: ". $fPass1 ."\nPassword: ". $fPass2,"FROM: You@yourserver.com");
echo "Your Password has been sent to ". $email .".";
Although, I wouldn't be surprised if it didn't.. uh.. I just read this up on a tutorial....
I really hope I helped.... :thumbsup:
Cloudski
07-27-2002, 04:33 PM
After posting.. I noticed an error :o
For the E-mail part of the message, it was supposed to be:
mail($email, "Your Password", "User Name: ". $fPass1["userid"] ."\nPassword: ". $fPass2["password"],"FROM: You@yourserver.com");
echo "Your Password has been sent to ". $email .".";
EthanX
07-27-2002, 04:51 PM
Hey, can anyone help me with my script. I'm trying to make a password script. http://www.codingforums.com/showthread.php?s=&threadid=2717
Trusten
07-27-2002, 05:23 PM
i get errors at this part
$myUser = mysql_query(SELECT userid FROM table WHERE userid='$name')
if(!myUser) {
echo("<P>Error performing query: " . mysql_error() . "</P>");
exit();
}
$myPass = mysql_query(SELECT password FROM table WHERE userid='$name')
if(!myPass) {
echo("<P>Error performing query: " . mysql_error() . "</P>");
exit();
}
$fpass1 = mysql_fetch_array($myUser)
$fpass2 = mysql_fetch_array($myPass)
are you sure this is right?
shouldn't it be something like ("SELECT*
or something?
Cloudski
07-27-2002, 05:26 PM
I guess.... :confused: I am just learning this as I go... I was looking at a tutorila they had on it, and trying to modify it to work for your situation... *sigh* Oh well, I wonder if we will ever get one of the great people who KNOW this stuff in here :)
EthanX
07-27-2002, 05:27 PM
I'll take a crack at it..
What do you want exacly?
Trusten
07-27-2002, 05:28 PM
i'm sorry. thanks though.
where's the tutorial, maybe i can fiddle with it.
Cloudski
07-27-2002, 05:40 PM
The Tutorial I was looking through is here:
http://www.mysql.com/articles/ddws/
I think I just missed some info... because I clicked on the link at the very bottom for chapter four or something like that...
EthanX
07-27-2002, 05:41 PM
I've got the code for you.. one minute.
Trusten
07-27-2002, 05:41 PM
k
EthanX
07-27-2002, 05:53 PM
Try this:
Form: (just HTML)
(Filename: forgotpass.php
<form name="forgotpassword" method="post" action="forgotpassword.php">
Email:
<input name="email" type="text" id="email">
<br>
<input type="submit" name="Submit" value="Submit">
</form>
Codin:
(Filename: forgotpassword.php)
<?php
// MySQL Information.
$db_host = "localhost"; // Host, 99% of the time this is localhost.
$db_username = "username"; // Username here
$db_password = "password"; // Password here
$linkID = @mysql_connect("$db_host", "$db_username", "$db_password");
// query commands
mysql_select_db("database", $linkID) or die(mysql_error()); // Database here
$resultID = mysql_query("SELECT user_id FROM userstable WHERE user_email = '$email'", $linkID) or die(mysql_error());
// End of query commands
// Check if Email is in database
$num_rows = mysql_num_rows($resultID);
$row = mysql_fetch_array($resultID);
$user_id = $row[0];
if ($user_id == "") {
print "We're sorry, your Email does not appear to be in our database.";
}
else {
// query commands
$resultID = mysql_query("SELECT user_password FROM userstable WHERE user_email = '$email'", $linkID) or die(mysql_error());
$row = mysql_fetch_array($resultID);
$passwordfromdb = $row[0];
// End of query commands
// Send Password to email
mail($email, "Your Password", "Password: ". $passwordfromdb .", "FROM: You@yourserver.com");
echo "Your Password has been sent to ". $email .".";
}
}
// End of Send Password to email
mysql_close($linkID);
?>
Hope that works :thumbsup:
Cloudski
07-27-2002, 07:44 PM
:) I never would have come up with anything like that ;)
Well, one thing is for sure.. EthanX has a lot more experience than I do.
EthanX
07-27-2002, 08:12 PM
Well.. I wouldn't say that.. I've never made a PHP script send mail before... so I have no idea if this will even work completely.
Trusten
07-28-2002, 03:10 AM
it gives me an error before the passwordphp even loads. the error is here.
mail($email, "Your Password", "Password: ". $passwordfromdb .", "FROM: You@yourserver.com");
EthanX
07-28-2002, 04:28 AM
okay, I'll have to look this up. because I've never used mail before.. BRB :-D
Cloudski
07-28-2002, 04:34 AM
Well, since we are just using a variable... why don't we just do this....
mail($email, "Your Password", "Password: $passwordfromdb", "FROM: You@yourserver.com");
echo "Your Password has been sent to $email ";
EthanX
07-28-2002, 04:38 AM
Here's the basic mail structure.
mail(string to, string subject, string message, string
[additional_headers]);
I know the error in that of what you have, take the ['email']['/email'] tags that vB added.
mail($email, "Your Password", "Password: ". $passwordfromdb .", "FROM: emailhere");
Good Luck :thumbsup:
Trusten
07-28-2002, 04:43 AM
hustin, we have a problem.
it's not decrypting the password when it sends it to me.
should i start a new topic?
it's sending me the encrypted pwd.
:(
EthanX
07-28-2002, 04:46 AM
oh.... let me check up on how to decript.
Cloudski
07-28-2002, 04:48 AM
Um, couldn't you just do:
md5($passwordfromdb);
Or whatever the ecrypt thingy is .. :p
Before you send it to the e-mail???
EthanX
07-28-2002, 04:50 AM
thought that incripted it?
EthanX
07-28-2002, 04:52 AM
<?php
// MySQL Information.
$db_host = "localhost"; // Host, 99% of the time this is localhost.
$db_username = "username"; // Username here
$db_password = "password"; // Password here
$linkID = @mysql_connect("$db_host", "$db_username", "$db_password");
// query commands
mysql_select_db("database", $linkID) or die(mysql_error()); // Database here
$resultID = mysql_query("SELECT user_id FROM userstable WHERE user_email = '$email'", $linkID) or die(mysql_error());
// End of query commands
// Check if Email is in database
$num_rows = mysql_num_rows($resultID);
$row = mysql_fetch_array($resultID);
$user_id = $row[0];
if ($user_id == "") {
print "We're sorry, your Email does not appear to be in our database.";
}
else {
// query commands
$resultID = mysql_query("SELECT user_password FROM userstable WHERE user_email = '$email'", $linkID) or die(mysql_error());
$row = mysql_fetch_array($resultID);
$passwordfromdb = $row[0];
$passwordtosend = md5($passwordfromdb);
// End of query commands
// Send Password to email
mail($email, "Your Password", "Password: ". $passwordrosend .", "FROM: emailhere");
echo "Your Password has been sent to ". $email .".";
}
}
// End of Send Password to email
mysql_close($linkID);
?>
Cloudski
07-28-2002, 04:52 AM
Um... maybe it decripts it, if it is already encrypted??
EthanX
07-28-2002, 04:53 AM
Worth a try. check previouse post.
Trusten
07-28-2002, 04:54 AM
didn't work. i changed $passwordfromdb to md5($passwordfromdb)
and all it did was put the encrypted password into the ( ) brackets
Trusten
07-28-2002, 04:59 AM
no good. i changed the code a bit cuz there was an error on like 36 again. the password sends, but it doesn't decrypt it.
:(
EthanX
07-28-2002, 05:00 AM
I have to find the code for decripting.
Trusten
07-28-2002, 05:02 AM
Ok, this is what i want to do.....
A. I want the scripts to do the
<?$php_SELF?> if possible. Because I can customize those.
B. I want that the person enters their email address and username or maybe just email address and it takes them to a prompt of their hint question.
C. Once they answer the hint, I want to send their passwords to them through email.
D. If this could all be on the same script that would be great.
E. I want that if they enter bad info or incorrect info, they are able to refresh (or whatever) and try again.
Here are my table infos.
User_id: the number they are, in other words, the 5th person, etc. etc.
userid: this is the user name they chose.
hintquestion: this is their hint question
hintanswer: this is the answer
password: this is their password. It's encyrpted with MD5
on second through, could i get a script that would either have them enter their user name, or their email address. perferably user name.
I'D REALLY APPRECIATE THE HELP. Thank you
EthanX
07-28-2002, 05:04 AM
Problem.... Still can't decrypt the incrypted password.
Trusten
07-28-2002, 05:09 AM
oh. anyway they can just change the pwd then?
EthanX
07-28-2002, 05:10 AM
Sure if we don't show the password that they have we can have it so they can change the password... couldn't be to hard, I have ideas of how to do it already.
Trusten
07-28-2002, 05:40 AM
ok, here's an idea. this, what it does is that it resets the user password and sends it to them.
<?
/* forgot_password.php (c) 2000 Ying Zhang (ying@zippydesign.com)
*
* TERMS OF USAGE:
* This file was written and developed by Ying Zhang (ying@zippydesign.com)
* for educational and demonstration purposes only. You are hereby granted the
* rights to use, modify, and redistribute this file as you like. The only
* requirement is that you must retain this notice, without modifications, at
* the top of your source code. No warranties or guarantees are expressed or
* implied. DO NOT use this code in a production environment without
* understanding the limitations and weaknesses pretaining to or caused by the
* use of these scripts, directly or indirectly. USE AT YOUR OWN RISK!
*/
/******************************************************************************
* MAIN
*****************************************************************************/
include("../application.php");
/* form has been submitted, check if it the user login information is correct */
if (match_referer() && isset($HTTP_POST_VARS)) {
$frm = $HTTP_POST_VARS;
$errormsg = validate_form($frm, $errors);
if (empty($errormsg)) {
$username = get_username($HTTP_POST_VARS["email"]);
reset_user_password($username);
$DOC_TITLE = "MyMarket Password Recovery";
include("$CFG->templatedir/header.php");
include("templates/forgot_password_success.php");
include("$CFG->templatedir/footer.php");
die;
}
}
include("templates/forgot_password_form.php");
/******************************************************************************
* FUNCTIONS
*****************************************************************************/
function validate_form(&$frm, &$errors) {
/* validate the forgot password form, and return the error messages in a string.
* if the string is empty, then there are no errors */
$errors = new Object;
$msg = "";
if (empty($frm["email"])) {
$errors->email = true;
$msg .= "You did not specify your email address";
} elseif (! email_exists($frm["email"])) {
$errors->email = true;
$msg .= "The specified email address is not on file";
}
return $msg;
}
function get_username($email) {
/* get the username based on an email address */
$qid = db_query("SELECT username FROM users WHERE email = '$email'");
$user = db_fetch_object($qid);
return $user->username;
}
?>
is there any way we can chop that up and bastardize it?
Trusten
07-28-2002, 05:41 AM
this one is for changing passwords. i'm no good at this, so i'll fiddle with it. any help would be appreciated.
<?
/* change_password.php (c) 2000 Ying Zhang (ying@zippydesign.com)
*
* TERMS OF USAGE:
* This file was written and developed by Ying Zhang (ying@zippydesign.com)
* for educational and demonstration purposes only. You are hereby granted the
* rights to use, modify, and redistribute this file as you like. The only
* requirement is that you must retain this notice, without modifications, at
* the top of your source code. No warranties or guarantees are expressed or
* implied. DO NOT use this code in a production environment without
* understanding the limitations and weaknesses pretaining to or caused by the
* use of these scripts, directly or indirectly. USE AT YOUR OWN RISK!
*/
/******************************************************************************
* MAIN
*****************************************************************************/
include("../application.php");
require_login();
/* form has been submitted, check if it the user login information is correct */
if (match_referer() && isset($HTTP_POST_VARS)) {
$frm = $HTTP_POST_VARS;
$errormsg = validate_form($frm, $errors);
if (empty($errormsg)) {
update_password($frm["newpassword"]);
$noticemsg = "Password change successful";
}
}
$DOC_TITLE = "Change Password";
include("$CFG->templatedir/header.php");
include("$CFG->templatedir/form_header.php");
include("templates/change_password_form.php");
include("$CFG->templatedir/footer.php");
/******************************************************************************
* FUNCTIONS
*****************************************************************************/
function validate_form(&$frm, &$errors) {
/* validate the forgot password form, and return the error messages in a string.
* if the string is empty, then there are no errors */
$errors = new Object;
$msg = "";
if (empty($frm["oldpassword"])) {
$errors->oldpassword = true;
$msg .= "You did not specify your old password";
} elseif (! password_valid($frm["oldpassword"])) {
$errors->oldpassword = true;
$msg .= "Your old password is invalid";
} elseif (empty($frm["newpassword"])) {
$errors->newpassword = true;
$msg .= "You did not specify your new password";
} elseif (empty($frm["newpassword2"])) {
$errors->newpassword2 = true;
$msg .= "You did not confirm your new password";
} elseif ($frm["newpassword"] != $frm["newpassword2"]) {
$errors->newpassword = true;
$errors->newpassword2 = true;
$msg .= "Your new passwords do not match";
}
return $msg;
}
function password_valid($password) {
/* return true if the user's password is valid */
global $SESSION;
$username = $SESSION["user"]["username"];
$password = md5($password);
$qid = db_query("SELECT 1 FROM users WHERE username = '$username' AND password = '$password'");
return db_num_rows($qid);
}
function update_password($newpassword) {
/* set the user's password to the new one */
global $SESSION;
$username = $SESSION["user"]["username"];
$newpassword = md5($newpassword);
$qid = db_query("UPDATE users SET password = '$newpassword' WHERE username = '$username'");
}
?>
oh, here's the form for it.
<form name="entryform" method="post" action="<?=$ME?>">
<table>
<tr>
<td class=label>Old Password:</td>
<td><input type="password" name="oldpassword" size=25>
<?err($errors->oldpassword)?>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td class=label>New Password:</td>
<td><input type="password" name="newpassword" size=25>
<?err($errors->newpassword)?>
</td>
</tr>
<tr>
<td class=label>Confirm Password:</td>
<td><input type="password" name="newpassword2" size=25>
<?err($errors->newpassword2)?>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Change Password">
<input type="reset" value="Reset">
</td>
</table>
</form>
EthanX
07-28-2002, 06:01 AM
Here we go :-D
Form: (HTML)
(Filename: forgotpass.php )
<form name="forgotpassword" method="post" action="forgotpassword.php">
Email:
<input name="email" type="text" id="email">
<br>
<input type="submit" name="Submit" value="Submit">
</form>
Codin:
(Filename: forgotpassword.php )
<?php
// Varables
$fromemail = "you@domain.com"; // Email address who it's from.
$scripturl = "http://www.domain.com/forgotpassword.php"; // The Full path to this file.
$table = "userstable"; // The table name.
// MySQL Information.
$db_host = "localhost"; // Host, 99% of the time this is localhost.
$db_username = "username"; // Username here
$db_password = "password"; // Password here
$database = "database"; // Database name
$linkID = @mysql_connect("$db_host", "$db_username", "$db_password");
mysql_select_db("$database", $linkID) or die(mysql_error()); // Database here
// Actions
if ($action == "change")
{
?>
<form method="post" action="forgotpassword.php?action=changepassword">
<input type="hidden" name="$email">
<input type="hidden" name="$pass">
New Password: <input type="text" name="newpass">
<input type="submit" name="Submit" value="Change Password">
</form>
<?php
}
else
{
if ($action == "changepassword")
{
// incrypted password
$mpassword = md5($newpass);
// query commands
$resultID = mysql_query("UPDATE $table SET password = '$mpassword' WHERE user_email = '$email' && user_password = '$pass'", $linkID) or die(mysql_error());
// End of query commands
if($resultID == TRUE)
{
print "you password has been changed.";
die();
}
else
{
print "Your password was not changed, please try again.";
die();
}
}
else
{
// query commands
$resultID = mysql_query("SELECT user_id FROM $table WHERE user_email = '$email'", $linkID) or die(mysql_error());
// End of query commands
// Check if Email is in database
$num_rows = mysql_num_rows($resultID);
$row = mysql_fetch_array($resultID);
$user_id = $row[0];
if ($user_id == "") {
print "We're sorry, your Email does not appear to be in our database.";
}
else {
// query commands
$resultID = mysql_query("SELECT user_password FROM $table WHERE user_email = '$email'", $linkID) or die(mysql_error());
$row = mysql_fetch_array($resultID);
$passwordfromdb = $row[0];
// End of query commands
// Send Password to email
mail($email, "Your Password", "go to ". $scripturl ."?action=change&email=". $email ."&pass=". $passwordfromdb ." to change your password.", "FROM: $fromemail");
echo "A email on changing your password has been sent to ". $email .".";
}
}
}
// End of Send Password to email
mysql_close($linkID);
?>
Once again I hope this work, any questions on it just ask.
AIM: jaehrhard
Email: MasterEthan@msn.com
Good Luck :thumbsup:
Trusten
07-28-2002, 06:02 AM
i don't see you on aim
EthanX
07-28-2002, 06:03 AM
LOL, didn't see your post :)
Was way to busy workin on this code... too bad :(
If your code doesn't work please try mine.
I'd love to know if mine works.
Trusten
07-28-2002, 09:30 AM
got it working!
do a dance,
make a little love
get down tonight
get down tonight
EthanX
07-28-2002, 03:35 PM
:cool: :thumbsup: :D :thumbsup: :cool:
Trusten
07-28-2002, 05:33 PM
think you could help on my latest prob?
EthanX
07-28-2002, 05:42 PM
Sure.
googlyamnesiac
03-20-2005, 05:44 PM
so how did you get it to decrypt the password it sent to the user? iv followed this all the way down - got it working to the last part! just wond decrypt the md5 value
googlyamnesiac
03-20-2005, 05:48 PM
oh - is ee this was posted a few years ago - can someone help??
anarchy3200
03-21-2005, 05:35 PM
Try to check if you are dragging up years old posts when your searching.
Anyway, for your problem MD5 is a hash rather than encryption so it is non reversible... you will not be able to decrypt it.
EthanX
11-19-2005, 08:01 PM
Yes. MD5 is not reversable.
Also the code I provided had an error in line 23 and 24. Simple.. but here's a correction for those who find this topic. Here is everything again... but it was php file that had the error as far as I can tell. Good luck:thumbsup:
Form: (HTML)
(Filename: forgotpass.php )
<form name="forgotpassword" method="post" action="forgotpassword.php">
Email:
<input name="email" type="text" id="email">
<br>
<input type="submit" name="Submit" value="Submit">
</form>
Codin:
(Filename: forgotpassword.php )
<?php
// Varables
$fromemail = "you@domain.com"; // Email address who it's from.
$scripturl = "http://www.domain.com/forgotpassword.php"; // The Full path to this file.
$table = "userstable"; // The table name.
// MySQL Information.
$db_host = "localhost"; // Host, 99% of the time this is localhost.
$db_username = "username"; // Username here
$db_password = "password"; // Password here
$database = "database"; // Database name
$linkID = @mysql_connect("$db_host", "$db_username", "$db_password");
mysql_select_db("$database", $linkID) or die(mysql_error()); // Database here
// Actions
if ($action == "change")
{
?>
<form method="post" action="forgotpassword.php?action=changepassword">
<input type="hidden" name="email" value="<?=$email?>">
<input type="hidden" name="pass" value="<?=$pass?>">
New Password: <input type="text" name="newpass">
<input type="submit" name="Submit" value="Change Password">
</form>
<?php
}
else
{
if ($action == "changepassword")
{
// incrypted password
$mpassword = md5($newpass);
// query commands
$resultID = mysql_query("UPDATE $table SET password = '$mpassword' WHERE user_email = '$email' && user_password = '$pass'", $linkID) or die(mysql_error());
// End of query commands
if($resultID == TRUE)
{
print "you password has been changed.";
die();
}
else
{
print "Your password was not changed, please try again.";
die();
}
}
else
{
// query commands
$resultID = mysql_query("SELECT user_id FROM $table WHERE user_email = '$email'", $linkID) or die(mysql_error());
// End of query commands
// Check if Email is in database
$num_rows = mysql_num_rows($resultID);
$row = mysql_fetch_array($resultID);
$user_id = $row[0];
if ($user_id == "") {
print "We're sorry, your Email does not appear to be in our database.";
}
else {
// query commands
$resultID = mysql_query("SELECT user_password FROM $table WHERE user_email = '$email'", $linkID) or die(mysql_error());
$row = mysql_fetch_array($resultID);
$passwordfromdb = $row[0];
// End of query commands
// Send Password to email
mail($email, "Your Password", "go to ". $scripturl ."?action=change&email=". $email ."&pass=". $passwordfromdb ." to change your password.", "FROM: $fromemail");
echo "A email on changing your password has been sent to ". $email .".";
}
}
}
// End of Send Password to email
mysql_close($linkID);
?>
Velox Letum
11-19-2005, 09:44 PM
MD5, SHA1, and other hashing encryptions are non-reversable, so I just send the user an email with a key to a change password page as EthanX did.
westmatrix99
12-26-2006, 10:18 PM
This is the .php page:
<?php require_once('Connections/cnfur.php'); ?>
<?php
$colname_rsforgot = "-1";
if (isset($_POST['email'])) {
$colname_rsforgot = (get_magic_quotes_gpc()) ? $_POST['email'] : addslashes($_POST['email']);
}
mysql_select_db($database_cnfur, $cnfur);
$query_rsforgot = sprintf("SELECT * FROM memlogin WHERE memEmail = '%s'", $colname_rsforgot);
$rsforgot = mysql_query($query_rsforgot, $cnfur) or die(mysql_error());
$row_rsforgot = mysql_fetch_assoc($rsforgot);
$totalRows_rsforgot = mysql_num_rows($rsforgot);
$name = $row_rsforgot['memUsername'];
$email = $_POST['email'];
$password = $row_rsforgot['memPassword '];
?>
<?php
$result = mysql_query($query_rsforgot, $cnfur) or die(mysql_error());
$affected_rows = mysql_num_rows($result);
if($affected_rows == 1) {
$mailto = $email;
$subject = "Forgot password:" ;
$uself = 1;
$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$from = "email@example.com";
$name = $row_rsforgot['memUsername'];
$email = $_POST['email'];
$password = $row_rsforgot['memPassword'];
$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['email'])) {
}
$messageproper =
"This message was sent from: Furkids \n".
"Name of sender: ".$name."\n" .
"Email of sender: ".$email."\n" .
"Password: \n". $password ."\n" .
mail("$email","Your Password","\n\nUsername: $name \nPasword: $password\n","From: $from");
echo "Your password has been sent to your email. <a href='javascript:self.close();'>Close window</a><br> Login once you have received your email.";
}
else
{
echo 'Unable to find selected username or email <a href="javascript:self.close();">Close window</a>.<br>';
}
?>
<?php
mysql_free_result($rsforgot);
?>
This script works on my machine offline but not online, any ideas would be great.
Thanks
West
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.