What are the six password encryption methods in php?
六种密码加密方式如下:
1、MD5加密
1 |
|
参数
str -- 原始字符串。
raw_output -- 如果可选的 raw_output 被设置为 TRUE,那么 MD5 报文摘要将以16字节长度的原始二进制格式返回。
这是一种不可逆加密,执行如下的代码
1 2 |
|
得到结果是e10adc3949ba59abbe56e057f20f883e
2、Crype加密
1 |
|
crypt() 返回一个基于标准 UNIX DES 算法或系统上其他可用的替代算法的散列字符串。
参数
str -- 待散列的字符串。
salt -- 可选的盐值字符串。如果没有提供,算法行为将由不同的算法实现决定,并可能导致不可预料的结束。
这是也一种不可逆加密,执行如下的代码
代码如下:
1 2 3 |
|
得到的结果是teMGKvBPcptKo
使用自动盐值的例子如下:
代码如下:
1 2 3 4 5 |
|
执行结果是输出 Password verified!
以不同散列类型使用 crypt()的例子如下:
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
其结果如下
1 2 3 4 5 6 |
|
(学习视频分享:php视频教程)
在 crypt() 函数支持多重散列的系统上,下面的常量根据相应的类型是否可用被设置为 0 或 1:
CRYPT_STD_DES - 基于标准 DES 算法的散列使用 "./0-9A-Za-z" 字符中的两个字符作为盐值。在盐值中使用非法的字符将导致 crypt() 失败。
CRYPT_EXT_DES - 扩展的基于 DES 算法的散列。其盐值为 9 个字符的字符串,由 1 个下划线后面跟着 4 字节循环次数和 4 字节盐值组成。它们被编码成可打印字符,每个字符 6 位,有效位最少的优先。0 到 63 被编码为 "./0-9A-Za-z"。在盐值中使用非法的字符将导致 crypt() 失败。
CRYPT_MD5 - MD5 散列使用一个以 $1$ 开始的 12 字符的字符串盐值。
CRYPT_BLOWFISH - Blowfish 算法使用如下盐值:“$2a$”,一个两位 cost 参数,“$” 以及 64 位由 “./0-9A-Za-z” 中的字符组合而成的字符串。在盐值中使用此范围之外的字符将导致 crypt() 返回一个空字符串。两位 cost 参数是循环次数以 2 为底的对数,它的范围是 04-31,超出这个范围将导致 crypt() 失败。
CRYPT_SHA256 - SHA-256 算法使用一个以 $5$ 开头的 16 字符字符串盐值进行散列。如果盐值字符串以 “rounds=
CRYPT_SHA512 - SHA-512 算法使用一个以 $6$ 开头的 16 字符字符串盐值进行散列。如果盐值字符串以 “rounds=
3、Sha1加密
1 |
|
参数
str -- 输入字符串。
raw_output -- 如果可选的 raw_output 参数被设置为 TRUE,那么 sha1 摘要将以 20 字符长度的原始格式返回,否则返回值是一个 40 字符长度的十六进制数字。
这是也一种不可逆加密,执行如下代码:
1 2 |
|
得到的结果是7c4a8d09ca3762af61e59520943dc26494f8941b
4、URL加密
1 |
|
此函数便于将字符串编码并将其用于 URL 的请求部分,同时它还便于将变量传递给下一页。
返回字符串,此字符串中除了 -_. 之外的所有非字母数字字符都将被替换成百分号(%)后跟两位十六进制数,空格则编码为加号(+)。此编码与 WWW 表单 POST 数据的编码方式是一样的,同时与 application/x-www-form-urlencoded 的媒体类型编码方式一样。由于历史原因,此编码在将空格编码为加号(+)方面与 RFC1738 编码不同。
1 |
|
解码给出的已编码字符串中的任何 %##。 加号('+')被解码成一个空格字符。
这是一种可逆加密,urlencode方法用于加密,urldecode方法用于解密,执行如下代码:
1 2 3 4 |
|
得到的结果如下
http%3A%2F%2Fwww.xxx.com%2FCraryPrimitiveMan%2F
http://www.xxx.com/CraryPrimitiveMan/
基于RFC 3986的加密URL的方法如下:
如下:
1 2 3 4 5 |
|
5、Base64信息编码加密
1 |
|
使用 base64 对 data 进行编码。
设计此种编码是为了使二进制数据可以通过非纯 8-bit 的传输层传输,例如电子邮件的主体。
Base64-encoded 数据要比原始数据多占用 33% 左右的空间。
string base64_decode ( string $data [, bool $strict = false ] )
对 base64 编码的 data 进行解码。
参数
data -- 编码过的数据。
strict -- 如果输入的数据超出了 base64 字母表,则返回 FALSE。
执行如下代码:
1 2 3 4 |
|
其结果如下
如下:
1 2 |
|
推荐phpass
经 phpass 0.3 测试,在存入数据库之前进行哈希保护用户密码的标准方式。 许多常用的哈希算法如 md5,甚至是 sha1 对于密码存储都是不安全的, 因为骇客能够使用那些算法轻而易举地破解密码。
对密码进行哈希最安全的方法是使用 bcrypt 算法。开源的 phpass 库以一个易于使用的类来提供该功能。
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
相关推荐:php教程
The above is the detailed content of What are the six password encryption methods in php?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

This chapter deals with the information about the authentication process available in CakePHP.
