Ver Mensaje Individual
  #4 (permalink)  
Antiguo 18/09/2013, 13:07
Avatar de Bathory666
Bathory666
 
Fecha de Ingreso: agosto-2012
Ubicación: Barcelona
Mensajes: 15
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Recuperar contraseña

Sí, el formulario está hecho...

Mira, esto es lo que tengo:

recuperar_contrasena.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>

</head>

<body>
<p>Escribe tu email y recibirás un link con la contraseña</p>
<form id="form1" name="form1" method="post" action="recuperar_contrasena_paso_1.php">
<p>Email:
<label for="textfield"></label>
<input type="text" name="textfield" id="textfield" />
</p>
<p>
<input type="submit" name="button" id="button" value="Enviar" />
</p>
</form>
<p>&nbsp;</p>
</body>
</html>

recuperar_contrasena_paso_1.php

<?php require_once('Connections/*********.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}


function generar_cadena_password($email)
{
global $*********, $database_*********;
$cadenarecuperacion = $_POST['strPassword'];

$updateSQL = sprintf("UPDATE tblregistrosclub SET strRecuperar=%s WHERE strEmail=%s",
GetSQLValueString($cadenarecuperacion, "text"),
GetSQLValueString($email, "text"));

$Result1 = mysql_query($updateSQL, $te*********) or die(mysql_error());

$para = $email;
$asunto = 'Recuperacion Password';
$mensaje .='Tu password es:' .$cadenarecuperacion;

// Para enviar correo HTML, la cabecera Content-type debe definirse
$cabeceras = 'MIME-Version: 1.0' . "\n";
$cabeceras .= 'Content-type: text/html; charset=iso-8859-1' . "\n";

// Cabeceras adicionales
//$cabeceras .= 'To: María <[email protected]>, Kelly <[email protected]>' . "\r\n";
$cabeceras .= 'From: nocontestar@*********.com' . "\n";

// Enviarlo
$para = $email;
mail($para, $asunto, $mensaje, $cabeceras);
}

$varEmail_DatosUsuario = "0";
if (isset($_POST['textfield'])) {
$varEmail_DatosUsuario = $_POST['textfield'];
}
mysql_select_db($database_*********, $*********);
$query_DatosUsuario = sprintf("SELECT * FROM tblregistrosclub WHERE tblregistrosclub.strEmail=%s", GetSQLValueString($varEmail_DatosUsuario, "int"));
$DatosUsuario = mysql_query($query_DatosUsuario, $*********) or die(mysql_error());
$row_DatosUsuario = mysql_fetch_assoc($DatosUsuario);
$totalRows_DatosUsuario = mysql_num_rows($DatosUsuario);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>

</head>

<body>
<?php if ($totalRows_DatosUsuario == 1){
generar_cadena_password($_POST["textfield"]);
?>
<p>Se ha enviado un email con tu contraseña.</p>
<?php }
else
{?>
No existe este email en la BD. <a href="recuperar_contrasena.php">Inténtalo de nuevo</a>
<?php }?>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($DatosUsuario);
?>

Llevo muy poco con php y hay algunas cosillas que aun me cuestan, sorry :(