Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [kohana] hasła
blokern
post 25.01.2021, 13:13:39
Post #1





Grupa: Zarejestrowani
Postów: 107
Pomógł: 0
Dołączył: 27.02.2008

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


Hej, musze na nowo postawic serwis ktory obecnie stoi na Kohana
mam problem z haslami.
do generowania hasel Kohana wykorzystuje to:
  1. function hash_password($password, $salt = FALSE)
  2. {
  3. if ($salt === FALSE)
  4. {
  5. // Create a salt seed, same length as the number of offsets in the pattern
  6. $salt = substr($this->hash(uniqid(NULL, TRUE)), 0, count($this->_config['salt_pattern']));
  7. }
  8.  
  9. // Password hash that the salt will be inserted into
  10. $hash = $this->hash($salt.$password);
  11.  
  12. // Change salt to an array
  13. $salt = str_split($salt, 1);
  14.  
  15. // Returned password
  16. $password = '';
  17.  
  18. // Used to calculate the length of splits
  19. $last_offset = 0;
  20.  
  21. foreach ($this->_config['salt_pattern'] as $offset)
  22. {
  23. // Split a new part of the hash off
  24. $part = substr($hash, 0, $offset - $last_offset);
  25.  
  26. // Cut the current part out of the hash
  27. $hash = substr($hash, $offset - $last_offset);
  28.  
  29. // Add the part to the password, appending the salt character
  30. $password .= $part.array_shift($salt);
  31.  
  32. // Set the last offset to the current offset
  33. $last_offset = $offset;
  34. }
  35.  
  36. // Return the password, with the remaining hash appended
  37. return $password.$hash;
  38. }


a plik auth.php

  1.  
  2. return array
  3. (
  4. 'driver' => 'ORM',
  5. 'hash_method' => 'sha1',
  6. 'salt_pattern' => '1, 3, 5, 9, 14, 15, 20, 21, 28, 30',
  7. 'lifetime' => 1209600,
  8. 'session_key' => 'auth_user',
  9. 'users' => array
  10. (
  11. // 'admin' => '***',
  12. ),
  13. );


a hasla w bazie są o 10 znaków dluzsze niz te wygenerowane metoda sha1 poniewaz jezeli dobrze rozumiem funkcja dodaje cos na koncu wykorzystuja salt?


jak moge zamienic sha1($haslo) tak zeby dzialalo z tym wyzej i generowalo hasla ktore pasuja do starej bazy?
dziekuje



--------------------
www.Opiekuj.pl
Go to the top of the page
+Quote Post
vokiel
post 25.01.2021, 15:44:17
Post #2





Grupa: Zarejestrowani
Postów: 2 592
Pomógł: 445
Dołączył: 12.03.2007

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


Musisz mieć okres przejściowy w którym będziesz sprawdzał hasła starą metodą i aktualizował w bazie do nowej.

Czyli, wchodzi user na stronę logowania, podaje login/email i hasło. Sprawdzasz format hasła w bazie, czy jest już nowy czy stary. Jeśli stary to sprawdzasz hasło starą metodą i jeśli jest poprawne, to hashujesz je nową metodą i zapisujesz do bazy.

Z czasem, jak już będziesz miał wszystkie hasła skonwertowane to możesz starą metodę całkiem usunąć.


--------------------
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: 28.03.2024 - 12:47