Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Hashowanie haseł
rav1989
post
Post #1





Grupa: Zarejestrowani
Postów: 66
Pomógł: 0
Dołączył: 5.07.2007

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


Witam,

Napisałem sobie klasę do hashowania haseł

  1. class HashPassword{
  2. private $algo = '$2a$08$';
  3. private $seed = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  4. private $salt_len = 22;
  5.  
  6. private function makeSalt() {
  7. $salt = '';
  8. $seed = str_shuffle($this->seed);
  9. for ($i = 0; $i < $this->salt_len; $i++) {
  10. $salt .= substr($this->seed, rand(0, (strlen($seed)-1)), 1);
  11. }
  12. return $salt;
  13. }
  14.  
  15. public function makeHash($password) {
  16. $pass = crypt($password, $this->algo.$this->makeSalt());
  17. $length = ((strlen($pass) - strlen($this->algo))*-1);
  18. $pass = substr($pass,$length);
  19. return base64_encode($pass);
  20. }
  21.  
  22. public function verifyHash($password, $hash) {
  23. $hash = $this->algo.base64_decode($hash);
  24. return ($hash == crypt($password, $hash));
  25. }
  26. }


(seed oraz długość soli są przykładowe (IMG:style_emoticons/default/smile.gif) )

Przykład wykorzystania:

  1. $pass = 'asdf';
  2. $hash_pass = new HashPassword();
  3.  
  4. $hash = $hash_pass->makeHash($pass);
  5. echo '<br>';
  6. echo $hash;
  7. echo '<br>';
  8. echo $hash_pass->verifyHash($pass, $hash)?'true':'false';


Jak uważacie czy hashowanie w ten sposób jest w miarę bezpieczne?

Pozdrawiam
Rav
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 22.08.2025 - 20:04