Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Authenticate user in PHP using PDO

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 142
    Comment on it

    Hi friends,
    If you are using PDO in php , Now you can Authenticate user using simple code.

    include 'conn.php';
    try
    {
        $username = $_POST['user'];
        $password = $_POST['pass'];
            $smt=$conn->prepare("SELECT * FROM signup WHERE username = '".$username."'");
            $smt->execute();
            $result=$smt->fetch(PDO::FETCH_OBJ);
            $prev=$result->Password;
            $usr=$result->Username;
               if(password_verify($password,$prev)& $username===$usr)
            {
            // Set username session variable
            $_SESSION['user'] = $username;
            // Jump to secured page
            header('location:index.php');
            exit;
        }
        else
        {
            $_SESSION['login-error']="Incorrect username or password";
            header('location:signin.php');
            exit;
        }
    }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: