Login User PHP

Asked

Viewed 228 times

0

I’m making the following code PHP

public function Login($uname,$umail,$upass)
{
    try
    {
        $stmt = $this->conn->prepare("SELECT usersid, user, email, password FROM user WHERE user=:uname OR email=:umail");
        $stmt->bindparam(":uname", $uname);
        $stmt->bindparam(":umail", $umail);
        $stmt->execute();
        $userRow=$stmt->fetch(PDO::FETCH_ASSOC);            
        if($stmt->rowCount() == 1)
        {               
            if(password_verify($upass, $userRow['password']))
            {                           
                $_SESSION['user_session'] = $userRow['usersid'];
                return true;
            }
            else
            {
                return false;
            }

        }           
    }
    catch(PDOException $e)
    {
        echo $e->getMessage();
    }
}

PHP INDEX

session_start();
require_once("class.user.php");
$login = new USER();

if($login->is_loggedin()!="")
{
    $login->redirect('home.php');
}

if(isset($_POST['btn-login']))
{
    $uname = strip_tags($_POST['txt_uname_email']);
    $umail = strip_tags($_POST['txt_uname_email']);
    $upass = strip_tags($_POST['txt_password']);    

    if($login->Login($uname,$umail,$upass))
    {
        $login->redirect('home.php');
    }
    else
    {
        $error = "Sem Autenticação ";
    }       

}

HTML INDEX

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" media="screen">
<link rel="stylesheet" href="style.css" type="text/css"/>
</head>
<body>

<div class="signin-form">

    <div class="container">


       <form class="form-signin" method="post" id="login-form">

        <h2 class="form-signin-heading">Access Painel</h2><hr />

        <div id="error">
        <?php
            if(isset($error))
            {
                ?>
                <div class="alert alert-danger">
                   <i class="glyphicon glyphicon-warning-sign"></i> &nbsp; <?php echo $error; ?> !
                </div>
                <?php
            }
        ?>
        </div>

        <div class="form-group">
        <input type="text" class="form-control" name="txt_uname_email" placeholder="Usu&aacute;rio ou Email" required />
        <span id="check-e"></span>
        </div>

        <div class="form-group">
        <input type="password" class="form-control" name="txt_password" placeholder="Senha" />
        </div>

        <hr />

        <div class="form-group">
            <button type="submit" name="btn-login" class="btn btn-default">
                    <i class="glyphicon glyphicon-log-in"></i> &nbsp; Login
            </button>
        </div>  
        <br />
            <label><a href="sign-up.php">Registrar</a></label>
      </form>

    </div>

</div>

</body>
</html>

But it’s not logging in, it’s going all the information to the Login function, doing a var_dump it goes up to $userRow=$stmt->fetch(PDO::FETCH_ASSOC); with all the information. What I think is catching is password_verify.

  • Going through this validation? if($stmt->rowCount() == 1) I usually use Count, like this: if (Count($userRow) > 1) {

  • You used password_hash before entering into the database?

  • @Déboracastro has already tried it, but it did not work.

  • @Willian yes it is hashed "$new_password = password_hash($upass, PASWORD_DEFAULT);"

No answers

Browser other questions tagged

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