php密码对称encrypt加密

  /**
     * 对用户的密码进行加密
     * @param $password
     * @param $encrypt //传入加密串,在修改密码时做认证
     * @return array/password
     */
    function password($password, $encrypt='') {
        $pwd = array();
        $pwd['encrypt'] =  $encrypt ? $encrypt : create_randomstr(); 
        $pwd['password'] = md5(md5(trim($password)).$pwd['encrypt']);
        return $encrypt ? $pwd['password'] : $pwd;
    }
    /**
     * 生成随机字符串
     * @param string $lenth 长度
     * @return string 字符串
     */
    function create_randomstr($lenth = 6) {
        return random($lenth, '123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ');
    }
 
  
原文地址:https://www.cnblogs.com/chenggege/p/7761279.html