Advertisement
Guest User

Untitled

a guest
Mar 1st, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. id name email pasword
  2. 1 andrew email@example.com hashed password
  3. 2 mike email2@example.com hashed password
  4.  
  5. class Database {
  6. private $host = DB_HOST;
  7. private $user = DB_USER;
  8. private $pass = DB_PASS;
  9. private $dbname = DB_NAME;
  10.  
  11. private $dbh;
  12. private $error;
  13. private $stmt;
  14.  
  15. public function __construct() {
  16. // Set DSN
  17. $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbname;
  18. // Set options
  19. $options = array (
  20. PDO::ATTR_PERSISTENT => true,
  21. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
  22. );
  23. // Create a new PDO instanace
  24. try {
  25. $this->dbh = new PDO ($dsn, $this->user, $this->pass, $options);
  26. } // Catch any errors
  27. catch ( PDOException $e ) {
  28. $this->error = $e->getMessage();
  29. }
  30. }
  31.  
  32.  
  33. public function query($query) {
  34. $this->stmt = $this->dbh->prepare($query);
  35. }
  36.  
  37.  
  38. public function bind($param, $value, $type = null) {
  39. if (is_null ( $type )) {
  40. switch (true) {
  41. case is_int ( $value ) :
  42. $type = PDO::PARAM_INT;
  43. break;
  44. case is_bool ( $value ) :
  45. $type = PDO::PARAM_BOOL;
  46. break;
  47. case is_null ( $value ) :
  48. $type = PDO::PARAM_NULL;
  49. break;
  50. default :
  51. $type = PDO::PARAM_STR;
  52. }
  53. }
  54. $this->stmt->bindValue ( $param, $value, $type );
  55. }
  56.  
  57.  
  58. public function execute(){
  59. return $this->stmt->execute();
  60. }
  61.  
  62.  
  63. public function resultset(){
  64. $this->execute();
  65. return $this->stmt->fetchAll(PDO::FETCH_OBJ);
  66. }
  67.  
  68.  
  69.  
  70. public function single(){
  71. $this->execute();
  72. return $this->stmt->fetch(PDO::FETCH_OBJ);
  73. }
  74.  
  75.  
  76. public function rowCount(){
  77. return $this->stmt->rowCount();
  78. }
  79.  
  80. public function login($email){
  81. $this->db->query("SELECT * FROM users
  82. WHERE email = :email
  83. ");
  84.  
  85. //Bind Values
  86. $this->db->bind(':email', $email);
  87. $row = $this->db->single();
  88.  
  89. //Check Rows
  90. if($this->db->rowCount() > 0){
  91. $this->setUserData($row);
  92. return true;
  93. } else {
  94. return false;
  95. }
  96.  
  97. }
  98. public function bringpassword($email1){
  99. $this->db->query("SELECT pasword FROM users
  100. WHERE email = :email
  101. ");
  102. $this->db->bind(':email',$email1);
  103. $results = $this->db->resultset();
  104. while($r = $results){
  105. $results=$r["pasword"];
  106. return $results;
  107. }
  108.  
  109. }
  110.  
  111. $email=$_POST['user_email3'];
  112. $user= new User;
  113. $password1 = $_POST['user_password2'];
  114. $hash = $user->bringpassword($email);
  115. if($user->login($email) && strlen($_POST['user_password2'])>5 && password_verify($password1, $hash)){
  116. $_SESSION['loggedin'] = true;
  117. $_SESSION['username'] = $username;
  118. $_SESSION["email"]=$emailc;
  119. redirect('index.php');
  120. }else{
  121. echo $hash;
  122. redirect('register.php','The email and password combination is incorrect!', 'error1');
  123.  
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement