Jump to content

Password reset help


NLT

Recommended Posts

Hello, I've come to ask you 2 things :P

 

I've coded a little script where it will send you a md5 string so you can click that and it'll send you a random password. But, when I type in my email or anyone else email in the form, it emails it. Even if it's not found in database. Another thing, the $user query isn't working, when I submit the form and I get "Thank you Resource id #6, a confirmation link has been sent to your email."

 

Could you tell me what's wrong with the above?

And how could I get it so it emails from a specific email?

 

Thanks. here's the code.

<?php

$host="localhost"; // Host name 
$username="user"; // Mysql username 
$password="pass"; // Mysql password 
$db_name="db"; // Database name 


//Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect to server"); 
mysql_select_db("$db_name")or die("cannot select DB");

$email=$_POST['email'];

$tbl_name=users;

$sql="SELECT mail FROM $tbl_name WHERE mail='$email'";
$result=mysql_query($sql);

$query_user="SELECT username FROM $tbl_name WHERE mail='$email'";
$user=mysql_query($query_user);


$confirmation=md5(uniqid(rand()));
$hotel_name=Hotel;

// Email
$to=$email;

$subject="Password Reset - $hotel_name";

$header="test";
$message="Your confirmation link\r\n";
$message.="Click on this link to to have a password sent to you\r\n";
$message.="http://fustigate.net/confirmation.php?code=$confirmation";

$sentmail = mail($to,$subject,$header,$message);


if($sentmail){
echo "Thank you $user, a confirmation link has been sent to your email.";
}
?>

Link to comment
Share on other sites

change to:

<?php
$query_user="SELECT username FROM $tbl_name WHERE mail='$email'";
$query=mysql_query($query_user);
$row = mysql_fetch_array($query);
$user = $row['username'];
?>

and:

$header="From: <your email address here>\r\n";

Link to comment
Share on other sites

Hello. I've done that, the username thing worked, but the mail from doesn't. It still says fustigat@s​rv42.hostin​g24.com when I want it to come from my email.

 

Thanks in advance.

 

I should also add, the header just shows at the bottom of the email.

Link to comment
Share on other sites

Ahh, that is great!

 

How could I make it display an error for any email that isn't in the database rather than sending it out anyway? Because right now if you type in any email it'll send you the password link and things.

Link to comment
Share on other sites

do you mean something like this?

<?php

$host="localhost"; // Host name 
$username="fustigat_lol"; // Mysql username 
$password="lol123"; // Mysql password 
$db_name="fustigat_phoenix"; // Database name 


//Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect to server"); 
mysql_select_db("$db_name")or die("cannot select DB");

$email=$_POST['email'];

$tbl_name=users;

$sql="SELECT mail FROM $tbl_name WHERE mail='$email'";
$result=mysql_query($sql);

if(mysql_num_rows($result)== 0)
{
		echo 'You did not submit a valid email';	
}
else {

	$query_user="SELECT username FROM $tbl_name WHERE mail='$email'";
	$user=mysql_query($query_user);


	$confirmation=md5(uniqid(rand()));
	$hotel_name=Hotel;

	// Email
	$to=$email;

	$subject="Password Reset - $hotel_name";

	$header="From: fustigate@fustigate.net\r\n";
	$message="Your confirmation link\r\n";
	$message.="Click on this link to to have a password sent to you\r\n";
	$message.="http://fustigate.net/confirmation.php?code=$confirmation";

	$sentmail = mail($to,$subject,$message,$header);


	if($sentmail){
	echo "Thank you $user, a confirmation link has been sent to your email.";
	}
}
?>

Link to comment
Share on other sites

Another problem in confirmation.php

<?
include('config.php');
$confirmation=$_GET['code'];

$table1="pass_reset";

$selectkey="SELECT * FROM $table1 WHERE confirm_code =$confirmation'";
$gotkey=mysql_query($selectkey);


if($gotkey){
$count=mysql_num_rows($gotkey);
}
if($count==1){
$rows=mysql_fetch_array($gotkey);
$email=$rows['email'];
}
$random_password=md5(uniqid(rand()));
$new_password=substr($random_password, 0, ;

$table2="users";
$updpass="UPDATE `users` SET password='$new_password' WHERE mail='$email'";
?>

 

it's not updating users  :shrug:

Link to comment
Share on other sites

It's still not updating the only 1 user. If I removed the $mail bit it will update all users (Which it should) but I can't get it to just update the one.

 

I should add, I want it to make the password in the database md5, but I want it to send the email with plaintext (needs to be created)

Link to comment
Share on other sites

Last one, and I should be fine. I asked my mate about generating a random plain and md5 password.

Plain for the email, md5 for the database. He gave me

$plain_password = passGen();
$md_password   = md5($plain_password);

I'm not sure if that's right or what, but I'm guessing something by there is wrong because I'm getting an error with them.

Fatal error: Call to undefined function passgen() in /home/fustigat/public_html/forgotpass/confirmation.php on line 22

 

I think after this is done, the script is finished

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.