Rybat
New Members-
Posts
9 -
Joined
-
Last visited
Rybat's Achievements
Member (2/5)
0
Reputation
-
Done that but it gives me ```die('Incorrect username / password combination!');``` yet i have registered a correct password and username combination. ``` <?php if(isset($_POST['login'])){ $username = $_POST['username']; $password = $_POST['password']; $errors = array(); $sql = "SELECT * FROM `users` where `username`=:username "; $stmt = $dbh->prepare($sql); $stmt->execute(array(':username' => $username, )); $user = $stmt->fetch(PDO::FETCH_ASSOC); if($user === false){ echo "no password";; } else{ $validPassword = password_verify($_POST['password'], $password ); if($validPassword){ $_SESSION['id'] = $user['id']; $_SESSION['logged_in'] = time(); header('Location: http://localhost/auth/login.php'); exit; } else{ die('Incorrect username / password combination!'); } } }```
-
I tried the code differently using password verify but does not go further from echo "no password" could I have done a mistake i am not seeing here is the code ``` <?php ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL); session_start(); include_once 'connect/conn.php'; ?> <?php if(isset($_POST['login'])){ $username = $_POST['username']; $password = $_POST['password']; $errors = array(); $sql = "SELECT * FROM `users` where `username`=:username and `password`=:password"; $stmt = $dbh->prepare($sql); $stmt->execute(array(':username' => $username, ':password' => $password )); $user = $stmt->fetch(PDO::FETCH_ASSOC); if($user === false){ echo "no password";; } else{ $validPassword = password_verify($passwordAttempt, $user['password']); if($validPassword){ $_SESSION['user_id'] = $user['id']; $_SESSION['logged_in'] = time(); header('Location: http://localhost/auth/login.php'); exit; } else{ die('Incorrect username / password combination!'); } } }```
-
``` <?php ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL); session_start(); include_once 'connect/conn.php'; ?> <?php if(isset($_POST['login'])){ $username = $_POST['username']; $password = $_POST['password']; $msg = ''; $hash = password_hash($password, PASSWORD_DEFAULT); $sql = "SELECT * FROM `users` where `username`=:username and `password`=:password"; $stmt = $dbh->prepare($sql); $stmt->execute(array(':username' => $username,':password' => $hash )); $count = $stmt->rowCount(); if ($count > 0){ $_SESSION["username"] = $_POST["username"]; die(header('Location: http://localhost/auth/login.php')); }else{ $msg = '<label>Wrong Data</label>'; } } ?>```
-
Much thanks for the help!
-
I did remove the try/catch logic and it worked. The $result was supposed to be $result = "<p style='color:green;'>Registration Successful</p>"; but it gave me $result = "<p style='color:green;'>An error occured: </p>"; Here is the code after removing try /catch include_once 'resource/database.php'; if(isset($_POST['email'])){ $email = $_POST['email']; $username = $_POST['username']; $password = $_POST['password']; $sqlInsert = "INSERT INTO users (username, email, password, join_date) VALUES (:username, :email, :password, now())"; $statement = $dbh->prepare($sqlInsert); $statement->execute(array(':username' => $username, ':email' => $email, ':password' => $password, )); if ($statement ->rowCount() == 1){ $result = "<p style='color:green;'>Registration Successful</p>"; } else { $result = "<p style='color:green;'>" . $statement->rowCount() . "</p>"; } $result = "<p style='color:green;'>An error occured: </p>"; }
-
I did read it but I was not getting, it could you send me a link so that I could understand better....Thanks!!
-
I agree with you all about not using password_hash() and password_verify() because this is just a demo, still new to PHP though before I embark on it I wanted to taste what i have first done. I did echo it <?php if(isset($result)) echo $result; ?> @ginerjmand @Barand I did this still no difference PS - If you're posting here you should be using: error_reporting(E_ALL); ini_set('display_errors', '1'); at the top of ALL php code while you develop it! Why are you not checking the result of your prepare call or your execute call? If you RTFM you would see that they both return values that will tell you if they succeeded? how do you go about this....
-
My display_errors are ON Any other possible way it is not inserting data and also not displaying errors.
-
I am making a login system but upon inserting data no response and no errors. Please help! my database connection code <?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "user_login"; try { //creating connection to mysql $dbh = new PDO("mysql: host=$servername;dbname=user_login", $username, $password); // set the PDO error mode to exception $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); exit; } ?> my signup.php <?php include_once 'resource/database.php'; if(isset($_POST['email'])){ $email = $_POST['email']; $username = $_POST['username']; $password = $_POST['password']; try { $sqlInsert = "INSERT INTO user_login (username, email, password, join_date) VALUES (:username, :email, :password, now())"; $statement = $dbh->prepare($sqlInsert); $statement->execute(array(':username' => $username, ':email' => $email, ':password' => $password, )); if ($statement ->rowCount() == 1){ $result = "<p style='color:green;'>Registration Successful</p>"; } } catch(PDOException $e) { $result = "<p style='color:green;'>An error occured: " . $e->getMessage() . "</p>"; exit; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Register Page</title> </head> <body> <h2> User Authenticatication System</h2> <h3>Registration Form</h3> <?php if(isset($result)) echo $result; ?> <form action="" method="POST"> <table> <tr> <td>Email:</td> <td><input type="text" name="email" value=""></td> </tr> <tr> <td>Username:</td> <td><input type="text" name="username" value=""></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="password" value=""></td> </tr> </table> <input type="submit" name="submit" value="Signup"> </form> <p><a href="http://localhost/auth/index.php"> Back to Homepage </a></p> </body> </html> what i am missing because there no errors and data is not inserted it give me a blank page upon clicking signup
