functions used to encrypt password in php?

后端 未结 3 754
我寻月下人不归
我寻月下人不归 2021-01-29 12:22

I am programming a PHP site that allows users to register,I\'m using codeigniter php and I want to know the best function to encrypt passwords and what difference between this f

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-29 13:10

    Use PHPass: http://www.openwall.com/phpass/

    The preferred (most secure) hashing method supported by phpass is the OpenBSD-style Blowfish-based bcrypt, also supported with our public domain crypt_blowfish package (for C applications), and known in PHP as CRYPT_BLOWFISH, with a fallback to BSDI-style extended DES-based hashes, known in PHP as CRYPT_EXT_DES, and a last resort fallback to MD5-based salted and variable iteration count password hashes implemented in phpass itself (also referred to as portable hashes).

    Put it in application/third_party, and use vanilla PHP to load it (not CI's loader):

    require_once APPPATH.'third_party/phpass-0.3/PasswordHash.php';
    $hash_iterations = 100;
    $portable_hashes = FALSE;
    $phpass = new PasswordHash($hash_iterations, $portable_hashes);
    

    Example usage:

    // Hash a password before storing it in the DB
    $hashed_password = $phpass->HashPassword($user_input);
    
    // Check a given password against a stored hashed password
    $is_valid = $phpass->CheckPassword($user_input, $stored_hash_of_password);
    

提交回复
热议问题