Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.74 KB | None | 0 0
  1. registrieren.php
  2.  
  3. <div class="box">
  4.  
  5. <h2>Registrieren</h2>
  6.  
  7. <form class="registrieren" action="includes/registrieren.inc.php" method="post">
  8. <input type="text" name="uid" placeholder="Benutzername">
  9. <input type="text" name="mail" placeholder="E-Mail">
  10. <input type="password" name="pwd" placeholder="Passwort">
  11. <input type="password" name="pwd-repeat" placeholder="Passwort wiederholen">
  12. <button type="submit" name="registrieren-submit">Registrieren</button>
  13. </form>
  14.  
  15. </div><!--end .box-->
  16.  
  17.  
  18. registrieren.inc.php
  19.  
  20.  
  21. if(isset($_POST['registrieren-submit'])){
  22.  
  23. // incl. DB connection
  24. include "db.php";
  25.  
  26.  
  27. //Übergabe POST registrieren.php , POST
  28. $username = $_POST['uid'];
  29. $email = $_POST['mail'];
  30. $password = $_POST['pwd'];
  31. $passwordRepeat = $_POST['pwd-repeat'];
  32.  
  33. // Prüfe ob INPUT befüllt und Valide
  34. if(empty($username) || empty($email) || empty($password) || empty($passwordRepeat)){
  35. header("Location: ../registrieren.php?error=emptyfields&uid=".$username."&mail=".$email);
  36. exit();
  37. }
  38. else if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
  39. header("Location: ../registrieren.php?error=invalidmail&uid=".$username);
  40. exit();
  41. }
  42. else if(!preg_match("/^[a-zA-Z0-9]*$/", $username)){
  43. header("Location: ../registrieren.php?error=invalidmail&uid=".$email);
  44. exit();
  45. }
  46. else if ($password !==$passwordRepeat){
  47. header("Location: ../registrieren.php?error=passwordcheck&uid=".$username."&email=".$email);
  48. exit();
  49. }
  50. else {
  51.  
  52. $sql = "SELECT uidUsers FROM users WHERE uidUsers=?";
  53. $stmt = mysqli_stmt_init($mysqli);
  54. if(!mysqli_stmt_prepare($stmt, $sql)){
  55. header("Location: ../registrieren.php?error=sqlerror");
  56. exit();
  57. }
  58. else{
  59. mysqli_stmt_bind_param($stmt, "s", $username);
  60. mysqli_stmt_execute($stmt);
  61. mysqli_stmt_store_result($stmt);
  62. $resultCheck = mysqli_stmt_num_rows($stmt);
  63. if($resultCheck > 0){
  64. header("Location: ../registrieren.php?error=usertaken&email=".$email);
  65. exit();
  66. }
  67. else{
  68. $sql = "INSERT INTO users (uidUsers, emailUsers, pwdUsers) VALUES (?, ?, ?) ";
  69. $stmt = mysqli_stmt_init($mysqli);
  70. if(!mysqli_stmt_prepare($stmt, $sql)){
  71. header("Location: ../registrieren.php?error=sqlerror");
  72. exit();
  73. }
  74. else{
  75. $hashedPwd = password_hash($password, PASSWORD_DEFAULT);
  76.  
  77. mysqli_stmt_bind_param($stmt, "sss", $username, $email, $hashedPwd);
  78. mysqli_stmt_execute($stmt);
  79. header("Location: ../registrieren.php?signup=success");
  80. exit();
  81. }
  82.  
  83. }
  84. }
  85.  
  86. }
  87. mysqli_stmt_close($stmt);
  88. mysqli_close($mysqli);
  89.  
  90. }
  91. else{
  92. header("Location: ../index.php");
  93. exit();
  94.  
  95. }
  96.  
  97.  
  98. /*
  99. Soweit funktioniert alles
  100. */
  101.  
  102.  
  103.  
  104. ////////////////
  105.  
  106. Login.php
  107.  
  108. <div class="box">
  109. <h2>Login System </h2>
  110. <?php echo $msg; ?>
  111. <form class="login" action="includes/login.inc.php" method="post">
  112. <input type="text" name="mailuid" placeholder="Benutzername oder E-Mail...">
  113. <input type="password" name="pwd" placeholder="Passwort">
  114. <button type="submit" name="login-submit">Einloggen</button>
  115. </form>
  116.  
  117. <a href="registrieren.php">Registrieren</a>
  118.  
  119. <form class="logout" action="includes/logout.inc.php" method="post">
  120. <button type="submit" name="logout-submit">Ausloggen</button>
  121. </form>
  122.  
  123. </div><!--end .box-->
  124.  
  125.  
  126. login.inc.php
  127.  
  128. if(isset($_POST['login-submit'])){
  129.  
  130. // incl. DB connection
  131. include "db.php";
  132.  
  133. $mailuid = $_POST['mailuid'];
  134. $password = $_POST['pwd'];
  135.  
  136.  
  137. if(empty($mailuid) || empty($password)){
  138. header("Location: ../index.php?error=emtyfields");
  139. exit();
  140. }
  141. else{
  142. $sql = "SELECT * FROM users WHERE uidUsers=? OR emailUsers=?";
  143. $stmt = mysqli_stmt_init($mysqli);
  144. if(!mysqli_stmt_prepare($stmt, $sql)){
  145. header("Location: ../index.php?error=sqlerror");
  146. exit();
  147. }
  148. else{
  149.  
  150. mysqli_stmt_bind_param($stmt, "ss" , $mailuid, $password );
  151. mysqli_stmt_execute($stmt);
  152. $result = mysqli_stmt_get_result($stmt);
  153.  
  154. if($row = mysqli_fetch_assoc($result)){ /*Fehler : evtl hier?*/
  155.  
  156. $pwdCheck = password_verify($password, $row['pwdUsers']);
  157.  
  158.  
  159. if($pwdCheck == false){
  160.  
  161. header("Location: ../index.php?error=wrongpwd");
  162. exit();
  163. }
  164. else if ($pwdCheck == true){
  165.  
  166. session_start();
  167. $_SESSION['userId'] = $row['idUsers'];
  168. $_SESSION['userUId'] = $row['uidUsers'];
  169.  
  170. header("Location: ../index.php?login=success");
  171. exit();
  172. }
  173.  
  174. }else{
  175. header("Location: ../index.php?error=nouser");
  176. exit();
  177.  
  178. }
  179. }
  180. }
  181.  
  182.  
  183. }
  184. else{
  185.  
  186. header("Location: ../index.php");
  187. exit();
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement