传统加密方式:

md5(密码+盐值);

$passwordString='your password';//你的密码$salt="your salt value";//盐值,增加复杂度(随机字串)$md5Password=md5($passwordString.$salt);

从理论上来说,md5不可逆,算是一种比较安全的加密方式。但是我要提醒的是,md5早在04年的时候就被中国人破解。一旦被人拖库的化,密码泄漏的可能性极大。

现在推荐一种新的处理方式:

密码散列算法函数

password_get_info — 返回指定哈希(hash)的相关信息

password_hash — 创建密码的哈希(hash)

password_needs_rehash — Checks if the given hash matches the given options

password_verify — 验证密码是否和哈希匹配

PHP5.5引入了Password Hashing函数,内核自带无需安装扩展。在PHP5.4下测试了下也可是可以的,使用前最好确认一下你当前的环境是否支持这些函数。

Password Hashing主要提供了4个函数

//查看哈希值的相关信息array password_get_info (string $hash) //创建hash密码string password_hash(string $password , integer $algo [, array $options ]) //判断hash密码是否特定选项、算法所创建boolean password_needs_rehash (string $hash , integer $algo [, array $options ]  boolean password_verify (string $password , string $hash)//验证密码

代码演示:

$password = 'password123456';//原始密码//使用BCRYPT算法加密密码$hash_password = password_hash($password, PASSWORD_BCRYPT);  if (password_verify($password , $hash_password)){   echo "密码匹配";}else{   echo "密码错误";}

重要特征:

通过password_hash加密后的密码,使用字典方式很难破解,因为每次生成的密码都是不一样的。破解这种加密只能采用暴力破解。

最后提醒:

加密方法再好,原始密码设置的过于简单都容易被破解,设置复杂的密码才是王道。

更多相关文章

  1. PHP 手册中的匿名函数关联用法分析
  2. php十进制转二进制不用函数
  3. PHP中常用的18个字符串函数
  4. 细数PHP中16个高危函数
  5. Linux服务器查看PHP是否支持mail()函数方法
  6. php实现共享内存进程通信函数之shm
  7. php date函数时间不对
  8. 【docker+gdb】调试 PHP 源码,看 strval 函数 C 实现
  9. php中base64加密解密函数实例(附代码)

随机推荐

  1. Android Studio 之 View组件常用属性及其
  2. In FontFamilyFont, unable to find attr
  3. 新浪微博Oauth2.0授权认证及SDK、API的使
  4. 【Android】Activity知识点
  5. android GridView 去掉自带点击边框效果
  6. ImageView、Bitmap的属性android:scaleTy
  7. Android_VectorDrawable矢量图与SVG
  8. Edittext 取消长按 复制和粘糊等操作
  9. Android_查看linux内核版本和android文件
  10. OpenMax