Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Password_hash
xazerek
post 25.09.2016, 11:53:58
Post #1





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 21.05.2013

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


Witam.
Co robię źle? Chcę wyciągnąć hasło z bazy danych i porównać je z tym wpisanym w formularzu logowania.



  1. <?php
  2. require_once("config.php");
  3.  
  4. $auth_host = $GLOBALS['auth_host'];
  5. $auth_user = $GLOBALS['auth_user'];
  6. $auth_pass = $GLOBALS['auth_pass'];
  7. $auth_dbase = $GLOBALS['auth_dbase'];
  8.  
  9.  
  10. $db = mysqli_connect($auth_host, $auth_user, $auth_pass,$auth_dbase) or die("Error " . mysqli_error($db));
  11.  
  12.  
  13. $user_name = mysqli_real_escape_string($db,$_POST['name']);
  14. $user_password = mysqli_real_escape_string($db,$_POST['password']);
  15.  
  16. $sql = mysqli_query($db,"SELECT * FROM account WHERE (user = '$user_name') AND banned IS NULL");
  17. $rows= mysqli_num_rows($sql);
  18.  
  19. if($rows > 0)
  20. {
  21. if(password_verify($user_password, $rows['password']))
  22. {
  23. echo "Logged In";
  24. }
  25. else
  26. {
  27. echo "Password Wrong";
  28. }
  29. }
  30. else
  31. {
  32. echo "Password Wrong";
  33. }
  34.  
  35. mysqli_close($db);
  36. ?>
Go to the top of the page
+Quote Post
viking
post 25.09.2016, 12:03:42
Post #2





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

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


Nic nie robisz z zapytaniem http://php.net/manual/en/mysqli-result.fetch-array.php


--------------------
Go to the top of the page
+Quote Post
xazerek
post 25.09.2016, 12:27:23
Post #3





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 21.05.2013

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


Nadal mam problem, nie wiem jak to mam zrobić.

  1. <?php
  2. require_once("config.php");
  3.  
  4. $auth_host = $GLOBALS['auth_host'];
  5. $auth_user = $GLOBALS['auth_user'];
  6. $auth_pass = $GLOBALS['auth_pass'];
  7. $auth_dbase = $GLOBALS['auth_dbase'];
  8.  
  9.  
  10. $db = mysqli_connect($auth_host, $auth_user, $auth_pass,$auth_dbase) or die("Error " . mysqli_error($db));
  11.  
  12.  
  13. $user_name = mysqli_real_escape_string($db,$_POST['name']);
  14. $user_password = mysqli_real_escape_string($db,$_POST['password']);
  15.  
  16. $sql = mysqli_query($db,"SELECT * FROM account WHERE (user = '$user_name') AND active IS NULL");
  17. $rows= mysqli_num_rows($sql);
  18.  
  19. $result = mysqli_query($db, $sql);
  20.  
  21. if($rows > 0)
  22. {
  23. $row = $result->fetch_array(MYSQLI_NUM);
  24.  
  25. if(password_verify($user_password, $row['password']))
  26. {
  27. echo "Logged In";
  28. }
  29. else
  30. {
  31. echo "Password Wrong";
  32. }
  33. }
  34. else
  35. {
  36. echo "Password Wrong";
  37. }
  38.  
  39. mysqli_close($db);
  40. ?>
Go to the top of the page
+Quote Post
viking
post 25.09.2016, 12:33:54
Post #4





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

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


Przecież są przykłady w dokumentacji. Najpierw wysyłasz query, query zwraca false lub result. Na result musisz użyć którąś z funkcji http://php.net/manual/en/class.mysqli-result.php


--------------------
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: 13.06.2025 - 09:10