(PHP) crypt () CRYPT_BLOWFISH ile nasıl kullanılır?

1 Cevap php

Birincisi, ben CRYPT_BLOWFISH kullanmak olduğunu görmek, i $ 2a $ ile başlayan bir 16 karakter tuz kullanmak gerekir. Ancak, php.net documentation for crypt() bazı sistemler CRYPT_BLOWFISH desteği yok diyor. Ne kadar sıklıkla durum olduğunu?

Sonraki, dokümanlar üzerinde kendi Örneğin, ben aşağıdaki gibi () kripti kullanın bakın:

<?php
$password = crypt('mypassword'); // let the salt be automatically generated

/* You should pass the entire results of crypt() as the salt for comparing a
   password, to avoid problems when different hashing algorithms are used. (As
   it says above, standard DES-based password hashing uses a 2-character salt,
   but MD5-based hashing uses 12.) */
if (crypt($user_input, $password) == $password) {
   echo "Password verified!";
}
?>

CRYPT_BLOWFISH kullanmak için, ben değiştirmeniz gereken tek şey bu yüzden gibi bunu yapmak için ilk satırı olacaktı;

crypt('mypassword', '$2a$07$usesomesillystringforsalt$')

ve sonra hatlarının kalanı olduğu gibi ince?

1 Cevap

PHP 5.3.0 crypt () önce işletim sistemi tarafından sağlanan lib kullanılır. Daha sonra algoritma mcrypt içinde uygulanan değilse (PHP için) uzantısı - Eğer önceki bir sürümünü kullanıyorsanız, o zaman (CRYPT_BLOWFISH sabitinin değerini kontrol edin) desteği varsa görmek için OS belgeleri kontrol etmek gerekir.

Eğer dokümanlar alıntı ettik örnek çok mantıklı görünmüyor:

  $stored_password=fetch_password($user);

  if (crypt($_REQUEST['password'],$stored_password)===$stored_password) {
      // note that crypt automatically extracts the salt and alogrithm type
      // from $stored_password
      ....

Sadece şifreyi oluştururken öneki ($ 2a $) belirtmeniz gerekir.

HTH

C.