Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> php logowanie
czarkowy
post
Post #1





Grupa: Zarejestrowani
Postów: 31
Pomógł: 1
Dołączył: 6.08.2017
Skąd: sdsadada

Ostrzeżenie: (0%)
-----


Siemka,
zrobiłem logowanie w php i jest mały problem, otóż za każdym raze jest niepoprawne logowanie, nie ważne czy dobry login i hasło czy zły

index.php
  1. <!DOCTYPE html>
  2. <html lang="pl">
  3. <meta charset="UTF-8">
  4. <title>Home Page</title>
  5. <link rel="stylesheet" href="index.css">
  6. <link rel="stylesheet" href="register.css">
  7. </head>
  8.  
  9. <form class="form-contener" action="signin.php" mathod="POST">
  10. <input type="text" class="inputText" name="username" placeholder="Your username">
  11. <input type="password" class="inputText" name="pass" placeholder="Your password">
  12. <button type="submit" class="inputSubmit" name="login">Sign In</button>
  13. </form>
  14.  
  15. </body>
  16. </html>


signin.php
  1. <?php
  2.  
  3. include 'db_connect.php';
  4.  
  5. $username = isset($_POST['username']) ? $_POST['username'] : "";
  6. $pass = isset($_POST['pass']) ? $_POST['pass'] : "";
  7.  
  8. $sql = "SELECT * FROM users WHERE username = '$username' AND pass = '$pass'";
  9.  
  10. $result = mysqli_query($conn, $sql);
  11.  
  12. if(!$row = mysqli_fetch_assoc($result)) {
  13. echo "Niezalogowany";
  14. } else {
  15. echo "Zalogowany";
  16. }


o co moze chodzic? :_:
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
viking
post
Post #2





Grupa: Zarejestrowani
Postów: 6 381
Pomógł: 1116
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


Tak czy inaczej zastosuj http://php.net/manual/en/mysqli-stmt.bind-param.php bo teraz masz otwarty skrypt na ataki.
Go to the top of the page
+Quote Post
czarkowy
post
Post #3





Grupa: Zarejestrowani
Postów: 31
Pomógł: 1
Dołączył: 6.08.2017
Skąd: sdsadada

Ostrzeżenie: (0%)
-----


Cytat(viking @ 6.08.2017, 18:08:53 ) *
Tak czy inaczej zastosuj http://php.net/manual/en/mysqli-stmt.bind-param.php bo teraz masz otwarty skrypt na ataki.


tak to powinno wyglądać? :

  1. <?php
  2.  
  3. if(isset($_SESSION['name'])){
  4. header('Location: index.php');
  5. }
  6.  
  7. include 'db_connect.php';
  8.  
  9. $firstname = isset($_POST['firstname']) ? $_POST['firstname'] : "";
  10. $username = isset($_POST['username']) ? $_POST['username'] : "";
  11. $email = isset($_POST['email']) ? $_POST['email'] : "";
  12. $pass = isset($_POST['pass']) ? $_POST['pass'] : "";
  13. $pass2 = isset($_POST['pass2']) ? $_POST['pass2'] : "";
  14.  
  15. if($pass == $pass2){
  16.  
  17. $username = addslashes($username);
  18. $pass = addslashes($pass);
  19.  
  20. $username = mysqli_real_escape_string($conn, $username);
  21. $pass = mysqli_real_escape_string($conn, $pass);
  22.  
  23. $pass = hash('sha256', '<>?/!@#$%^&*()-=+:'.$pass);
  24.  
  25. $stmt = mysqli_prepare($conn, "INSERT INTO users VALUES(?, ?, ?, ?)");
  26. mysqli_stmt_bind_param($stmt, $firstname, $username, $email, $pass);
  27.  
  28. /*$sql = "INSERT INTO users (firstname, username, email, pass) VALUES ('$firstname', '$username', '$email', '$pass')";
  29. $result = $conn->query($sql);
  30. */
  31. mysqli_stmt_execute($stmt);
  32.  
  33. $_SESSION['name'] = 'session: '.$username;
  34. $_SESSION['username'] = $username;
  35.  
  36. header("Location: index.php");
  37. }
  38.  
  39. mysqli_stmt_close($stmt);
  40. mysqli_close($conn);
  41.  


Ten post edytował czarkowy 7.08.2017, 20:34:14
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 8.10.2025 - 07:00