Welcome, Guest. Please login or register.

Login with username, password and session length
Pages: [1]   Go Down
Print
Topic: change account details w/ email confirmation  (Read 868 times)
« on: June 08, 2009, 10:56:34 AM »
madar1985 Offline
Newbie

View Profile
*
Posts: 3



I already have a site with users and everything.

I want to allow users to change their e-mail and passwords, but I want them to have to confirm it through e-mail.

I'm just not really sure how I should go about it.

I was considering generating a random string, then sending them an e-mail with a link containing that code, but that would require me to add 2 extra fields to the users table, one for the code and one for new e-mail/password, which seems like a waste.

Any one done this before, or have any suggestions?

I'm using php4 and mysql. This is more of a psuedocode question, rather than php, considering I'm fairly good with php.
Logged

 
« Reply #1 on: June 22, 2009, 05:52:30 AM »
n1tr0b Offline
Newbie

View Profile
*
Posts: 11



you dont need 2 more fields for MySQL Databases... here is some of my script that i always use

here is for changing the password with an email:
if(isset($_POST['changepassword']))
{

$current trim($_POST['current']);
$new trim($_POST['new']);
$confirm trim($_POST['confirm']);

$pw md5($current);

$query mysql_query("SELECT * FROM Users WHERE Password = '$pw' LIMIT 1") or die(mysql_error());

if(
mysql_num_rows($query) > 0)
{

while(
$row mysql_fetch_array($query))
{

if ( 
$_POST['new'] == $_POST['confirm'] )
{}else{

echo 
'<script>alert("Your passwords were not the same, please enter the same password in each field.");</script>';
echo 
'<script>history.back(1);</script>';
exit;

}

$password md5($new);

$do mysql_query("UPDATE Users SET Password = '$password' WHERE Password = '$pw' LIMIT 1") or die(mysql_error());
$dotwo mysql_query("UPDATE Users SET Activated = 0 WHERE Password = '$password' LIMIT 1") or die(mysql_error());
$send mail($row['Email'] , "Password changed" "Your password has been changed to: ".trim($_POST['new'])."\n\nYou can change it again via the members only panel, but first you must re-activate your account:\nhttp://avateinfo.kh3.us/activate.php?id=".$row['Actkey']."\n\nDo not reply to this email, it is automated. Thanks." "From: noreply@YOURSITE.COM");

if(((
$do)&&($dotwo)&&($send)))
{

echo 
'<script>alert("Password changed. You will now be logged out and you must re-activate your account, check your email, a confirmation email has been sent.");</script>';
echo 
'<script>location.replace("logout.php");</script>';

For Email Change
if(isset($_POST['changeemail']))
{

$current trim($_POST['current']);
$new trim($_POST['new']);
$confirm trim($_POST['confirm']);

$query mysql_query("SELECT * FROM Users WHERE Email = '$current' LIMIT 1") or die(mysql_error());

if(
mysql_num_rows($query) > 0)
{

while(
$row mysql_fetch_array($query))
{

if ( 
$_POST['new'] == $_POST['confirm'] )
{}else{

echo 
'<script>alert("Your email addresses were not the same, please enter the same email to confirm.");</script>';
echo 
'<script>history.back(1);</script>';
exit;

}

$do mysql_query("UPDATE Users SET Email = '$new' WHERE Email = '$current' LIMIT 1") or die(mysql_error());
$dotwo mysql_query("UPDATE Users SET Activated = 0 WHERE Email = '$new' LIMIT 1") or die(mysql_error());
$send mail($row['Email'] , "Email changed" "Your email has been changed to: ".trim($_POST['new'])."\n\nYou can change it again via the members only panel, but first you must re-activate your account:\nhttp://CHANGETHISURL.COM/activate.php?id=".$row['Actkey']."\n\nDo not reply to this email, it is automated. Thanks." "From: noreply@YOURSITE.COM");

if(((
$do)&&($dotwo)&&($send)))
{

echo 
'<script>alert("Email changed. You will now be logged out and you must re-activate your account, check your email, a confirmation email has been sent.");</script>';
echo 
'<script>location.replace("logout.php");</script>';



FOR ACTIVATING IT:
$id $_GET['id'];

$query mysql_query("SELECT * FROM Users WHERE Actkey = '$id' LIMIT 1") or die(mysql_error());
$row mysql_fetch_array($query);

if(
mysql_num_rows($query) > 0){

$user $row['id'];

$do mysql_query("UPDATE Users SET Activated = 1 WHERE id = '$user' LIMIT 1") or die(mysql_error());
$send mail($row['Email'] , "Activation Confirmation" "Thank you for activating your account, you are now fully registered and able to use our services.\n\nTo login, click the link below:\nhttp://avateinfo.kh3.us/members.avt" "FROM: noreply@avteinfo.kh3.us");

if((
$do)&&($send))
{

echo 
'<link href="style.css" rel="stylesheet" type="text/css">
<div id="success">
<p>Activation successful! A confirmation email has been dispatched. You can now login!</p>
<p><a href="login.php">Click here</a> to goto the login page.</p>
</div>'
;

} else {

echo 
'<link href="style.css" rel="stylesheet" type="text/css">
<div id="error">
<p>We are sorry, there appears to be an error processing your activation. Please try again later.</p>
</div>'
;

}

} else {

echo 
'<link href="style.css" rel="stylesheet" type="text/css">
<div id="error">
<p>Sorry, your activation code was incorrect. Please try again.</p>
</div>'
;

}

mysql_close($l);
Logged
 
Pages: [1]   Go Up
Print
Jump to: