Advertisement
Guest User

Untitled

a guest
Apr 16th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. <?php
  2.  
  3. define('DB_NAME','login');
  4. define('DB_SERVER','localhost');
  5. define('DB_USERNAME','root');
  6. define('DB_PASSWORD','');
  7.  
  8. class User{
  9. $dbConn = new PDO("mysql:host=".DB_SERVER.";dbname=".DB_NAME,DB_USERNAME,DB_PASSWORD);
  10. $dbConn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
  11.  
  12.  
  13. public function Login($name, $password){
  14. if(!empty($name) && !empty($password)){
  15. $statement = $dbConn->prepare("select * from users where name=? and password=?");
  16. $statement->bindParam(1, $name);
  17. $statement->bindParam(2, $password);
  18. $statement->execute();
  19.  
  20. if($statement->rowCount() == 1){
  21. echo "User verified, Access granted.";
  22. }else{
  23. echo "Incorrect username or password";
  24. }
  25. }else{
  26. echo "Please enter username and password";
  27. }
  28.  
  29. }
  30.  
  31.  
  32. }
  33.  
  34.  
  35. ?>
  36.  
  37. <?php
  38.  
  39. include_once('user.php');
  40.  
  41. if(isset($_POST['submit'])){
  42. $name = $_POST['user'];
  43. $password = $_POST['password'];
  44.  
  45. $object = new User();
  46. $object->Login($name, $password);
  47. }
  48.  
  49.  
  50. ?>
  51.  
  52. <html>
  53. <head>
  54. </head>
  55. <body>
  56. <form method="post" action="index.php">
  57. Username: <input type="text" name="user">
  58. Password: <input type="text" name="password">
  59. <input type="submit" name="submit" value="Login">
  60. </form>
  61. </body>
  62. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement