How do I put a password exchange method in my login system using ajax?

Asked

Viewed 13 times

0

My login system was done as follows:

On the home page of my website, we have:

insira o código aqui`<div class="tab-1 resp-tab-content" aria-labelledby="tab_item-0">
                            <div class="facts">
                            <div class="register">
                                    <form action="logado.php" method="post">            
                                    <input name="email" placeholder="Email" type="text" required="">                        
                <input name="senha" placeholder="Senha" type="password" required="">                                        
                <div class="sign-up">
                        <input type="submit" value="Entrar"/>
                                    </div>
                                    </form>
                                    </div>
                                    </div> 
                                    </div>

then the rest of the login is done in the logged in.php file:

<?php
     if(isset($_POST['email']))
     {
        
        $email = $_POST['email'];
        $senha = sha1($_POST['senha']);
        
        include("conectar.php");
        
        $sql = "select nome, senha as 'senha', cpf 
                from clientes 
                where email='$email'";
        
        //echo "$sql";
        
        $resultado = $conexao->query($sql);
        
        if($resultado->num_rows > 0)
        {
            $linha     = $resultado->fetch_object();
            
            $senhaBD = $linha->senha;
            $nome    = $linha->nome;
            $cpf    = $linha->cpf;
            
            if($senha == $senhaBD)
            {
                session_start();
                $_SESSION['logado'] = "sim";
                $_SESSION['nome']   = $nome;
                $_SESSION['cpf']   = $cpf;

                
                header("location:index.php");
            }
            else
            {
                echo '<div class="alert alert-warning">
                        <strong>Aviso!</strong> Senha ou Email inválido!
                     </div>';
                echo "<a href='index.php'>Voltar</a>";
            }
        }
        else
        {
            echo '<div class="alert alert-warning">
                        <strong>Aviso!</strong> Senha ou Email inválido!
                     </div>';
                echo "<a href='index.php'>Voltar</a>";
        }
     }
     else
     {
       echo"erro";
     }

   
  
    
?>

How to create a method to exchange the password using Ajax, in case the user has forgotten the password?

1 answer

0

You have to make a table to save the password exchange requests

this table would be something like this

change

  • id
  • user_id
  • secret code
  • date

when requesting the password exchange the system generates a random code and creates a new entry in this table

then send an email to the account owner saying "let’s reset the password? lalala" and this email has a link to your system and in the url you put a parameter with the secret code

displays a password reset form for user_id

but in morality does it just to study, when to do something serious has a lot of frameworks that abstract this part

peace

Browser other questions tagged

You are not signed in. Login or sign up in order to post.