1. Hash passwords mainly use one-way dispersion algorithms to create password dispersion.
In the password encryption mode database, the column storing the result can exceed 60 characters, and the varchar length needs to be set to 255.
<?php //Encryption function generatePassword($password) { return password_hash($password, PASSWORD_DEFAULT); } //Verification function verifyPassword($password, $hashPassword) { return password_verify($password, $hashPassword); } //Encryption result: $2y$10$.vGA1O9wmRjrwAVXD98HNOgsNpDczlqm3Jq7KnEd1rVAGv3Fykk1a
2. The md5 password is an asymmetric encryption. It's a good idea to add obfuscated strings when encrypting.
This should be the most common password encryption method.
This cryptographic method is actually very secure, as hash collisions can lead to vulnerabilities.
<?php //Encryption function md5_password($password, $hash = 'autofelix_') { return md5($hash . $password); } //Verify $userinfo = /** Query user information **/; if ($userinfo['password'] !== md5_password($password)) { /** Password error logic **/ } /** The password is correct, continue with the logic **/
The above are two methods for generating user passwords in php. I hope they will be helpful to everyone.