Foros del Web » Programando para Internet » PHP »

Como hacer esto?

Estas en el tema de Como hacer esto? en el foro de PHP en Foros del Web. Hola, tengo una pregunta, como hago lo siguiente: Quiero que en vez de generarse un random password, se genere un password md5 pero que provenga ...
  #1 (permalink)  
Antiguo 10/02/2010, 11:47
 
Fecha de Ingreso: enero-2010
Mensajes: 198
Antigüedad: 14 años, 3 meses
Puntos: 1
Como hacer esto?

Hola, tengo una pregunta, como hago lo siguiente: Quiero que en vez de generarse un random password, se genere un password md5 pero que provenga de la contraseña que ingrese el usuario.
Deberia agregar el campo password en el registro, pero como cambiaria en este codigo lo que quiero hacer.

Código:
<?php

define('INCLUDE_CHECK',true);

require 'connect.php';
require 'functions.php';
// Those two files can be included only if INCLUDE_CHECK is defined

session_start();

session_name('tzLogin');
// Starting the session

session_set_cookie_params(2*7*24*60*60);
// Making the cookie live for 2 weeks


if($_SESSION['id'] && !isset($_COOKIE['tzRemember']) && !$_SESSION['rememberMe'])
{
    // If you are logged in, but you don't have the tzRemember cookie (browser restart)
    // and you have not checked the rememberMe checkbox:

    $_SESSION = array();
    session_destroy();
    
    // Destroy the session
}


if(isset($_GET['logoff']))
{
    $_SESSION = array();
    session_destroy();
    
    header("Location: index.php");
    exit;
}

if($_POST['submit']=='Login')
{
    // Checking whether the Login form has been submitted
    
    $err = array();
    // Will hold our errors
    
    
    if(!$_POST['username'] || !$_POST['password'])
        $err[] = 'All the fields must be filled in!';
    
    if(!count($err))
    {
        $_POST['username'] = mysql_real_escape_string($_POST['username']);
        $_POST['password'] = mysql_real_escape_string($_POST['password']);
        $_POST['rememberMe'] = (int)$_POST['rememberMe'];
        
        // Escaping all input data

        $row = mysql_fetch_assoc(mysql_query("SELECT id,usr FROM tz_members WHERE usr='{$_POST['username']}' AND pass='".md5($_POST['password'])."'"));

        if($row['usr'])
        {
            // If everything is OK login
            
            $_SESSION['usr']=$row['usr'];
            $_SESSION['id'] = $row['id'];
            $_SESSION['rememberMe'] = $_POST['rememberMe'];
            
            // Store some data in the session
            
            setcookie('tzRemember',$_POST['rememberMe']);
        }
        else $err[]='Wrong username and/or password!';
    }
    
    if($err)
    $_SESSION['msg']['login-err'] = implode('<br />',$err);
    // Save the error messages in the session

    header("Location: index.php");
    exit;
}
else if($_POST['submit']=='Register')
{
    // If the Register form has been submitted
    
    $err = array();
    
    if(strlen($_POST['username'])<4 || strlen($_POST['username'])>32)
    {
        $err[]='Your username must be between 3 and 32 characters!';
    }
    
    if(preg_match('/[^a-z0-9\-\_\.]+/i',$_POST['username']))
    {
        $err[]='Your username contains invalid characters!';
    }
    
    if(!checkEmail($_POST['email']))
    {
        $err[]='Your email is not valid!';
    }
    
    if(!count($err))
    {
        // If there are no errors
        
        $pass = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
        // Generate a random password
        
        $_POST['email'] = mysql_real_escape_string($_POST['email']);
        $_POST['username'] = mysql_real_escape_string($_POST['username']);
        // Escape the input data
        
        
        mysql_query("    INSERT INTO tz_members(usr,pass,email,regIP,dt)
                        VALUES(
                        
                            '".$_POST['username']."',
                            '".md5($pass)."',
                            '".$_POST['email']."',
                            '".$_SERVER['REMOTE_ADDR']."',
                            NOW()
                            
                        )");
        
        if(mysql_affected_rows($link)==1)
        {
            send_mail(    '[email protected]',
                        $_POST['email'],
                        'Registration System Demo - Your New Password',
                        'Your password is: '.$pass);

            $_SESSION['msg']['reg-success']='We sent you an email with your new password!';
        }
        else $err[]='This username is already taken!';
    }

    if(count($err))
    {
        $_SESSION['msg']['reg-err'] = implode('<br />',$err);
    }    
    
    header("Location: index.php");
    exit;
}

$script = '';

if($_SESSION['msg'])
{
    // The script below shows the sliding panel on page load
    
    $script = '
    <script type="text/javascript">
    
        $(function(){
        
            $("div#panel").show();
            $("#toggle a").toggle();
        });
    
    </script>';
    
}
?>
Gracias.
  #2 (permalink)  
Antiguo 10/02/2010, 11:57
Avatar de maycolalvarez
Colaborador
 
Fecha de Ingreso: julio-2008
Ubicación: Caracas
Mensajes: 12.120
Antigüedad: 15 años, 9 meses
Puntos: 1532
Respuesta: Como hacer esto?

$pass=md5($_POST['password']) ¿no veo el inconveniente?
  #3 (permalink)  
Antiguo 10/02/2010, 11:57
Avatar de darkasecas  
Fecha de Ingreso: marzo-2005
Ubicación: SantaCata, NL, Mexico
Mensajes: 1.553
Antigüedad: 19 años, 1 mes
Puntos: 77
Respuesta: Como hacer esto?

pues al momento de insertar, en lugar de pasarle a la funcion md5 el pass qe genero, pasale el valor qe se envia del formulario en $_POST >_>

EDIT: woo! mensaje # 1000 :D
  #4 (permalink)  
Antiguo 10/02/2010, 12:09
 
Fecha de Ingreso: enero-2010
Mensajes: 198
Antigüedad: 14 años, 3 meses
Puntos: 1
Respuesta: Como hacer esto?

Cita:
Iniciado por maycolalvarez Ver Mensaje
$pass=md5($_POST['password']) ¿no veo el inconveniente?
Si, pasa que no se mandaban los datos. Gracias

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:53.