Guest User

Untitled

a guest
Nov 23rd, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.52 KB | None | 0 0
  1. <?php
  2.  
  3. if($_SERVER['REQUEST_METHOD'] == 'POST'){
  4.  
  5. $email = trim($_POST['email']);
  6.  
  7. try{
  8. $Query = "SELECT * FROM users WHERE email = :email";
  9. $statement = $conn->prepare($Query);
  10. $statement->bindValue(':email', $email);
  11. $statement->execute();
  12. $user = $statement->fetch(PDO::FETCH_ASSOC);
  13. $RowCount = $statement->rowCount();
  14. } catch (PDOerrorInfo $e){}
  15.  
  16. if( $RowCount == 0 ){
  17. // User doesn't exist
  18. $_SESSION['message'] = "Não existe um usuário com este e-mail.";
  19. header("location: error.php");
  20.  
  21. } else{ // User exists
  22.  
  23. if( password_verify($_POST['password'], $user['password'])){
  24. $_SESSION['email'] = $user['email'];
  25. $_SESSION['first_name'] = $user['first_name'];
  26. $_SESSION['last_name'] = $user['last_name'];
  27. $_SESSION['username'] = $user['username'];
  28. $_SESSION['img'] = $user['img'];
  29. $_SESSION['active'] = $user['active'];
  30. $_SESSION['logged_in'] = true;
  31. header("location: ../index.php");
  32. } else {
  33. $_SESSION['message'] = "Senha incorreta, tente novamente!";
  34. header("location: error.php");
  35. }
  36. }
  37. }
  38.  
  39. <?php
  40.  
  41. $img = rand(0,30);
  42. $first_name = trim($_POST['first_name']);
  43. $last_name = trim($_POST['last_name']);
  44. $username = trim($_POST['username']);
  45. $email = trim($_POST['email']);
  46. $password = password_hash($_POST['password'], PASSWORD_BCRYPT);
  47. $hash = md5( rand(0,1000) );
  48.  
  49. // Check if user with that email already exists
  50. $result = $conn->prepare("SELECT * FROM users WHERE email = :email");
  51. $result->bindParam(':email', $email);
  52. $result->execute();
  53. $RowCount = $result->rowCount();
  54.  
  55. if ( $RowCount > 0 ) {
  56. $_SESSION['message'] = 'Já existe um usuário com este e-mail!';
  57. header("location: error.php");
  58. } else {
  59. $sql = "INSERT INTO users (first_name, last_name, username, img, email, password, hash) VALUES (:first_name, :last_name, :username, :img, :email, :password, :hash)";
  60. $sql = $conn->prepare($sql);
  61. $sql->bindParam(':first_name', $first_name);
  62. $sql->bindParam(':last_name', $last_name);
  63. $sql->bindParam(':username', $username);
  64. $sql->bindParam(':img', $img);
  65. $sql->bindParam(':email', $email);
  66. $sql->bindParam(':password', $password);
  67. $sql->bindParam(':hash', $hash);
  68. $sql->execute();
  69.  
  70. }
  71.  
  72. <?php
  73. require 'db.php';
  74. session_start();
  75. if ( $_SERVER['REQUEST_METHOD'] == 'POST' )
  76. {
  77. $email = trim($_POST['email']);
  78. $result = $conn->prepare("SELECT * FROM users WHERE email = :email");
  79. $result->bindValue(':email', $email);
  80. $result->execute();
  81. $RowCount = $result->rowCount();
  82.  
  83. if ( $RowCount == 0 )
  84. {
  85. $_SESSION['message'] = "Não existe um usuário com este e-mail.";
  86. header("location: error.php");
  87. }
  88. else {
  89. $user = $result->fetch(PDO::FETCH_ASSOC);
  90. $email = $user['email'];
  91. $hash = $user['hash'];
  92. $first_name = $user['first_name'];
  93.  
  94. $_SESSION['message'] = "<p>Link de confirmação enviado para <span>$email</span>"
  95. . " clique no link para resetar a sua senha!</p>";
  96.  
  97. $to = $email;
  98. $subject = 'Resetar senha - AnimeFire';
  99. $message_body = '
  100. Olá '.$first_name.' :),
  101.  
  102. Você solicitou o resete de sua senha.
  103.  
  104. Clique no link para resetar:
  105.  
  106. https://localhost/login-system/reset.php?email='.$email.'&hash='.$hash;
  107.  
  108. mail($to, $subject, $message_body);
  109.  
  110. header("location: success.php");
  111. }
  112. }
  113. ?>
  114.  
  115. <?php
  116. require 'db.php';
  117. session_start();
  118. if( isset($_GET['email']) && !empty($_GET['email']) AND isset($_GET['hash']) && !empty($_GET['hash']) )
  119. {
  120. $email = trim($_GET['email']);
  121. $hash = trim($_GET['hash']);
  122.  
  123. $result = $conn->prepared("SELECT * FROM users WHERE email = :email AND hash = :hash");
  124. $result->bindValue(':email', $email);
  125. $result->bindValue(':hash', $hash);
  126. $result->execute();
  127. $RowCount = $result->rowCount();
  128.  
  129. if ( $RowCount == 0 )
  130. {
  131. $_SESSION['message'] = "A conta já foi verificada ou o URL é inválido!";
  132. header("location: error.php");
  133. }
  134. }else {
  135. $_SESSION['message'] = "A verificação falhou :/ tente novamente!";
  136. header("location: error.php");
  137. }
  138. ?>
  139.  
  140. <?php
  141. require 'db.php';
  142. session_start();
  143. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  144. if ( $_POST['newpassword'] == $_POST['confirmpassword'] ) {
  145.  
  146. $new_password = password_hash($_POST['newpassword'], PASSWORD_BCRYPT);
  147. $email = trim($_GET['email']);
  148. $hash = trim($_GET['hash']);
  149.  
  150. $sql = $conn->prepare("UPDATE users SET password = :new_password, hash = :hash WHERE email = :email");
  151. $sql->bindValue(':new_password', $new_password);
  152. $sql->bindValue(':hash', $hash);
  153. $sql->bindValue(':email', $email);
  154. $sql->execute();
  155.  
  156. if ( $conn->prepare($sql) ) {
  157.  
  158. $_SESSION['message'] = "Sua senha foi resetada com sucesso ^^";
  159. header("location: success.php");
  160.  
  161. }
  162. } else {
  163. $_SESSION['message'] = "As senhas não estão iguais, tente novamente!";
  164. header("location: error.php");
  165. }
  166. }
  167. ?>
  168.  
  169. <?php
  170. if ( $_SESSION['logged_in'] != 1 ) {
  171. $_SESSION['message'] = "Você precisa estar logado para vizualizar esta página!";
  172. header("location: error.php");
  173. }
  174. else {
  175. $first_name = $_SESSION['first_name'];
  176. $last_name = $_SESSION['last_name'];
  177. $email = $_SESSION['email'];
  178. $username = $_SESSION['username'];
  179. $img = $_SESSION['img'];
  180. }
  181. ?>
  182. <img src="img/avatar/<?= $img ?>.jpg">
  183. <h3 ><?= $username ?></h3>
  184. <h6 >Nome: <?= $first_name.' '.$last_name ?></h6>
  185. <h6 >Email: <?= $email ?></h6>
Add Comment
Please, Sign In to add comment