PHP is more secure than MD5 encryption method--hash password

Source: Internet
Author: User

Traditional encryption methods:

MD5 (password + salt value);

$passwordString = ' your password ';//Your password $salt= "your salt value";//salt, increase complexity (random string) $md 5password=md5 ($passwordString. $ SALT);

Theoretically speaking, MD5 is not reversible, which is a more secure encryption method. But I would like to remind that MD5 early in 04 was the Chinese cracked (please search the Shandong University Xiao). Once dragged into the library, the likelihood of a password leak is great.


A new approach is now recommended: password hashing algorithm functions
    • password_get_info-returns information about the specified hash (hash)

    • password_hash-creating a hash of the password (hash)

    • Password_needs_rehash-checks if the given hash matches the given options

    • password_verify-Verify that the password matches the hash



PHP5.5 introduces the password hashing function, the kernel comes with no need to install extensions. It is also possible to test under PHP5.4, before using it, it is best to confirm whether your current environment supports these functions.


Password hashing mainly provides 4 functions

View information about the hash value array Password_get_info (string $hash)//Create a hash password string Password_hash (string $password, Integer $algo [, Array $options])//Determine if the hash password is a specific option, the algorithm creates a Boolean Password_needs_rehash (String $hash, Integer $algo [, array $options] Boo Lean password_verify (String $password, String $hash)//Authentication password


Code Demo:

$password = ' password123456 ';//original password//use BCRYPT algorithm to encrypt password $hash_password = Password_hash ($password, Password_bcrypt); if ( Password_verify ($password, $hash _password)) {echo "Password match";} else{echo "Password Error";}


Important Features:

By Password_hash encrypted passwords, it is difficult to hack using a dictionary because each generated password is not the same. This encryption can only be cracked by brute force.


Last reminder:

Encryption method is good, the original password settings are too simple to be cracked, set a complex password is kingly.


This article is from the "My PHP path" blog, so be sure to keep this source http://phpme.blog.51cto.com/663593/1926557

PHP is more secure than MD5 encryption method--hash password

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.