Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> php logowanie
czarkowy
post 6.08.2017, 12:10:43
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
viking
post 6.08.2017, 15:48:47
Post #2





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Sprawdz co zwraca wynik zapytania. Dodatkowo powinieneś bindowac parametry. A hasło przez password_hash.


--------------------
Go to the top of the page
+Quote Post
czarkowy
post 6.08.2017, 16:09:24
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, 16:48:47 ) *
Sprawdz co zwraca wynik zapytania. Dodatkowo powinieneś bindowac parametry. A hasło przez password_hash.


bindowac parametry tzn?

i z hashowaniem to wiem, ale po co to teraz robić jak nic nawet nie dziala ;p

dodałem var_dump($result);
i zwraca mi to:
  1. E:\Programy\wamp64\www\testproject\signin.php:17:
  2. object(mysqli_result)[2]
  3. public 'current_field' => int 0
  4. public 'field_count' => int 5
  5. public 'lengths' => null
  6. public 'num_rows' => int 0
  7. public 'type' => int 0


w ogóle nie wiem czy to jakoś źle dane nie sa przesylane ;p
bo var_dump($username) i var_dump($pass) zwracają mi puste stringi

@edit

$username = isset($_POST['username']) ? $_POST['username'] : "";
$pass = isset($_POST['pass']) ? $_POST['pass'] : "";

tutaj chyba w ogóle username i pass nie sa rozpoznawane i po prostu program wybiera ostatnia opcje czyli pustego stringa ;x bo jak tam wpisalem poprawne dane to mozna sie zalogowac


Ten post edytował czarkowy 6.08.2017, 16:17:43
Go to the top of the page
+Quote Post
viking
post 6.08.2017, 16:16:45
Post #4





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Z tego wynika ze jest0 rekordów. Zrób var_dump($_POST).


--------------------
Go to the top of the page
+Quote Post
czarkowy
post 6.08.2017, 16:19:30
Post #5





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

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


Cytat(viking @ 6.08.2017, 17:16:45 ) *
Z tego wynika ze jest0 rekordów. Zrób var_dump($_POST).


var_dump($_POST) zwraca:
  1. E:\Programy\wamp64\www\testproject\signin.php:19:
  2. array (size=0)
Go to the top of the page
+Quote Post
markuz
post 6.08.2017, 16:31:17
Post #6





Grupa: Zarejestrowani
Postów: 1 240
Pomógł: 278
Dołączył: 11.03.2008

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


Masz literówkę, nie mathod tylko method (w formularzu html).


--------------------
Go to the top of the page
+Quote Post
czarkowy
post 6.08.2017, 16:34:14
Post #7





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

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


Cytat(markuz @ 6.08.2017, 17:31:17 ) *
Masz literówkę, nie mathod tylko method (w formularzu html).


...od 2 dni z tym się głowie i walcze...a tu takie małe gówienko..uhh
dzięki wielkie smile.gif
Go to the top of the page
+Quote Post
viking
post 6.08.2017, 17:08:53
Post #8





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
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 7.08.2017, 20:23:04
Post #9





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
viking
post 7.08.2017, 20:43:41
Post #10





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


W dokumentacji to na pewno tak nie wygląda więc masz odpowiedź. Wywal te add_slashes i escape stri ng dodatkowo.


--------------------
Go to the top of the page
+Quote Post
czarkowy
post 7.08.2017, 21:11:08
Post #11





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

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


Cytat(viking @ 7.08.2017, 21:43:41 ) *
W dokumentacji to na pewno tak nie wygląda więc masz odpowiedź. Wywal te add_slashes i escape stri ng dodatkowo.


dziwne to jest ;p

takie coś? :

  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. $pass = hash('sha256', '<>?/!@#$%^&*()-=+:'.$pass);
  18.  
  19. $stmt = mysqli_prepare($conn, "INSERT INTO users VALUES (?, ?, ?, ?)");
  20. mysqli_stmt_bind_param($stmt, 'ss', $firstname_stmt, $username_stmt, $email_stmt, $pass_stmt);
  21.  
  22. $firstname_stmt = $firstname;
  23. $username_stmt = $username;
  24. $email_stmt = $email;
  25. $pass_stmt = $pass;
  26.  
  27. mysqli_stmt_execute();
  28.  
  29. /*$sql = "INSERT INTO users (firstname, username, email, pass) VALUES ('$firstname', '$username', '$email', '$pass')";
  30. $result = $conn->query($sql);
  31. */
  32. $_SESSION['name'] = 'session: '.$username_stmt;
  33. $_SESSION['username'] = $username_stmt;
  34.  
  35. header("Location: index.php");
  36. }
  37.  
  38. mysqli_stmt_close($stmt);
  39. mysqli_close($conn);
  40.  

Go to the top of the page
+Quote Post
viking
post 8.08.2017, 05:42:02
Post #12





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Uruchomiłeś ten kod? Z dokumentacji: A string that contains one or more characters which specify the types for the corresponding bind variables. Ile masz bind values? Ja tam widzę 4. Najpierw podstawiasz zmienne, potem je tworzysz.
Definicja: bool mysqli_stmt_execute ( mysqli_stmt $stmt )

Ten post edytował viking 8.08.2017, 06:51:38


--------------------
Go to the top of the page
+Quote Post
czarkowy
post 8.08.2017, 10:37:24
Post #13





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

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


Cytat(viking @ 8.08.2017, 06:42:02 ) *
Uruchomiłeś ten kod? Z dokumentacji: A string that contains one or more characters which specify the types for the corresponding bind variables. Ile masz bind values? Ja tam widzę 4. Najpierw podstawiasz zmienne, potem je tworzysz.
Definicja: bool mysqli_stmt_execute ( mysqli_stmt $stmt )


no uruchamiam i kurde działa, wlasnie gdyby jakies bledy wyskakiwaly to łatwiej by to szlo ;p

teraz takie coś mam:

  1. <?php
  2.  
  3. if(isset($_SESSION['name'])){
  4. header('Location: index.php');
  5. }
  6.  
  7. include 'db_connect.php';
  8.  
  9. $stmt = mysqli_prepare($conn, "INSERT INTO users(firstname, username, email, pass) VALUES (?, ?, ?, ?)");
  10. mysqli_stmt_bind_param($stmt, 'ssss', $firstname_stmt, $username_stmt, $email_stmt, $pass_stmt);
  11.  
  12. $firstname_stmt = isset($_POST['firstname']) ? $_POST['firstname'] : "";
  13. $username_stmt = isset($_POST['username']) ? $_POST['username'] : "";
  14. $email_stmt = isset($_POST['email']) ? $_POST['email'] : "";
  15. $pass_stmt = isset($_POST['pass']) ? $_POST['pass'] : "";
  16. $pass2 = isset($_POST['pass2']) ? $_POST['pass2'] : "";
  17.  
  18. $pass_stmt = hash('sha256', '<>?/!@#$%^&*()-=+:'.$pass_stmt);
  19.  
  20. mysqli_stmt_execute($stmt);
  21.  
  22. $_SESSION['name'] = 'session: '.$username_stmt;
  23. $_SESSION['username'] = $username_stmt;
  24.  
  25. header("Location: index.php");
  26.  
  27. mysqli_stmt_close($stmt);
  28. mysqli_close($conn);
  29.  
Go to the top of the page
+Quote Post
viking
post 8.08.2017, 10:54:49
Post #14





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


A jak ma wywalić błędy skoro robisz przekierowanie


--------------------
Go to the top of the page
+Quote Post
czarkowy
post 8.08.2017, 11:11:26
Post #15





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

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


Cytat(viking @ 8.08.2017, 11:54:49 ) *
A jak ma wywalić błędy skoro robisz przekierowanie


wywalilem i tez nie ma zadnych

to wyzej jest okej czy nie?
Go to the top of the page
+Quote Post
nospor
post 8.08.2017, 11:17:03
Post #16





Grupa: Moderatorzy
Postów: 36 455
Pomógł: 6292
Dołączył: 27.12.2004




Cytat
no uruchamiam i kurde działa,
Sorki, ze sie wcinam w te interesujaca dyskusje ale skoro dziala to w czym problem?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post

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 Wersja Lo-Fi Aktualny czas: 26.04.2024 - 08:00