Home  >  Article  >  Backend Development  >  Detailed explanation of how to change password after postfixadmin forgets password_php example

Detailed explanation of how to change password after postfixadmin forgets password_php example

WBOY
WBOYOriginal
2016-08-04 08:56:531173browse

本文实例讲述了postfixadmin忘记密码后的修改密码方法。分享给大家供大家参考,具体如下:

Postfix Admin 是一个基于Web的 Postfix 邮件发送服务器的管理工具,可以直接管理 Postfix 的虚拟域名和用户。

由于有一段时间没使用postfixadmin增删用户了, 突然需使用时忘记了管理密码,  使用老外的方式直接在数据库里修改密码, 后登录成功

php源码:

<&#63;php
echo md5crypt("新密码");
// md5crypt
// Action: Creates MD5 encrypted password
// Call: md5crypt (string cleartextpassword)
function md5crypt($pw, $salt = "", $magic = "")
{
  $MAGIC = "$1$";
  if ($magic == "")
  {
    $magic = $MAGIC;
  }
  if ($salt == "")
  {
    $salt = create_salt();
  }
  $slist = explode("$", $salt);
  if (isset($slist[0]) && $slist[0] == "1")
  {
    $salt = $slist[1];
  }
  $salt = substr($salt, 0, 8);
  $ctx = $pw.$magic.$salt;
  $final = hex2bin(md5($pw.$salt.$pw));
  for ($i = strlen($pw); $i > 0; $i -= 16)
  {
    if ($i > 16)
    {
      $ctx .= substr($final,0,16);
    }
    else
    {
      $ctx .= substr($final,0,$i);
    }
  }
  $i = strlen($pw);
  while ($i > 0)
  {
    if ($i & 1)
    {
      $ctx .= chr(0);
    }
    else
    {
      $ctx .= $pw[0];
    }
    $i = $i >> 1;
  }
  $final = hex2bin(md5($ctx));
  for ($i=0; $i<1000; $i++)
  {
    $ctx1 = "";
    if ($i & 1)
    {
      $ctx1 .= $pw;
    }
    else
    {
      $ctx1 .= substr($final,0,16);
    }
    if ($i % 3)
    {
      $ctx1 .= $salt;
    }
    if ($i % 7)
    {
      $ctx1 .= $pw;
    }
    if ($i & 1)
    {
      $ctx1 .= substr($final, 0, 16);
    }
    else
    {
      $ctx1 .= $pw;
    }
    $final = hex2bin(md5($ctx1));
  }
  $passwd = "";
  $passwd .= to64(((ord($final[0]) << 16) | (ord($final[6]) << 8) | (ord($final[12]))), 4);
  $passwd .= to64(((ord($final[1]) << 16) | (ord($final[7]) << 8) | (ord($final[13]))), 4);
  $passwd .= to64(((ord($final[2]) << 16) | (ord($final[8]) << 8) | (ord($final[14]))), 4);
  $passwd .= to64(((ord($final[3]) << 16) | (ord($final[9]) << 8) | (ord($final[15]))), 4);
  $passwd .= to64(((ord($final[4]) << 16) | (ord($final[10]) << 8) | (ord($final[5]))), 4);
  $passwd .= to64(ord($final[11]), 2);
  return $magic.$salt.'$'.$passwd;
}
function create_salt()
{
  srand((double) microtime() * 1000000);
  return substr(md5(rand(0,9999999)), 0, 8);
}
// PHP around 5.3.8 includes hex2bin as native function - http://php.net/hex2bin
function hex2bin($str)
{
    $len = strlen($str);
    $nstr = "";
    for ($i = 0; $i < $len; $i += 2)
    {
      $num = sscanf(substr($str, $i, 2), "%x");
      $nstr .= chr($num[0]);
    }
    return $nstr;
}
function to64($v, $n)
{
  $ITOA64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  $ret = "";
  while (($n - 1) >= 0)
  {
    $n--;
    $ret .= $ITOA64[$v & 0x3f];
    $v = $v >> 6;
  }
  return $ret;
}

更多关于PHP相关内容感兴趣的读者可查看本站专题:《php加密方法总结》、《PHP编码与转码操作技巧汇总》、《php面向对象程序设计入门教程》、《PHP数学运算技巧总结》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《PHP数据结构与算法教程》、《php程序设计算法总结》、《php正则表达式用法总结》、及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn