0
    <?php
session_start();

//DB configuration Constants
define('_HOST_NAME_', 'localhost');
define('_USER_NAME_', 'user');
define('_DB_PASSWORD', '');
define('_DATABASE_NAME_', 'user');

//PDO Database Connection
try {
    $databaseConnection = new PDO('mysql:host=localhost; dbname=user; ', 'root', '');
    $databaseConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
    echo 'ERROR: ' . $e->getMessage();
}

if(isset($_POST['login'])){
    $errMsg = '';
    //username and password sent from Form
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);
    $hashpass = hash('sha512',$password);


    if($username == '')
        $errMsg .= 'You must enter your Username<br>';

    if($password == '')
        $errMsg .= 'You must enter your Password<br>';


    if($errMsg == ''){
        $records = $databaseConnection->prepare('SELECT user_id,user_name,user_password FROM  user WHERE user_name = :username');
        $records->bindParam(':username', $username);
        $records->execute();
        $results = $records->fetch(PDO::FETCH_ASSOC);                                           //line 91
        if(count($results) > 0 && password_verify($hashpass, $results['password'])){
            $_SESSION['username'] = $results['username'];
            header('location:index.php');
            exit;
        }else{
            $errMsg .= 'Username and Password are not found<br>';
        }
    }
}

hello, i have the username and the password hash in the dbh and i have this error: Notice: Undefined index: password in C:\wamp64\www\social-network\register.php on line 91 Call Stack # Time Memory Function Location

  • It looks like you don't handle for the case where `$username` is invalid. You simultaneously check for a result and the password verification. Split these up (check for an actual result). – Mike May 29 '18 at 13:20
  • ok i solv it ^^ if(count($results) > 0 && $hashpass == $results['user_password']){ – PeanutStick May 29 '18 at 13:44

0 Answers0