How does PHP encrypt and decrypt a string?

Source: Internet
Author: User
For e-commerce site users, the most important thing is the security of the account and password, if the account and password is not encrypted processing, will greatly increase the security risks, never let criminals open the way, so now the website development in order to ensure that the interests of users and privacy is not compromised, the user's account password to encrypt, In this chapter, we will take you to know how to encrypt and decrypt the password.

First we need to know that our password is a string, and the base64 encoding and decoding of the string can be implemented by PHP's pre-defined functions Base64_encode () and Base64_decode ().

Base64_encode () function

The base64 encoding of the character is implemented with the function Base64_encode (), with the following syntax:

Base64_encode (str);

This function implements the base64 encoding of the string str.

Base64_decode () function

We use the Base64_decode () function to decode a string with the following syntax:

Base64_decode (str);

Also function implementation to decrypt a string that has been base64 encoded

Two functions we have already introduced, so how exactly is it used? Look at the following example

Application examples

By the String function Base64_encode (), Base64_decode () to encrypt and decrypt the password, we encrypt the user's password and decrypt the code as follows:

<! DOCTYPE html>

When the "Submit" button is clicked, the password is encrypted and decrypted by the string function Base64_encode (), Base64_decode (), and the result is as follows:

PHP provides a lot of encryption and decryption functions, such as base64_encode () or MD5 (), etc., can be used in the actual use of a suitable function to choose the use. Read more about the PHP cryptographic functions topic

Related Article

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: 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.