search
Homephp教程php手册php生成随机密码函数(四款)

下面提供了四款php生成随机密码函数哦,方法简单实用是一款用户自定的加密函数,这样如果不知道你的加密算法是很难破解的。

方法一

 代码如下 复制代码

function generate_password( $length = 8 ) {
    // 密码字符集,可任意添加你需要的字符
    $chars = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_ []{}~`+=,.;:/?|';

    $password = '';
    for ( $i = 0; $i     {
        // 这里提供两种字符获取方式
        // 第一种是使用 substr 截取$chars中的任意一位字符;
        // 第二种是取字符数组 $chars 的任意元素
        // $password .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
        $password .= $chars[ mt_rand(0, strlen($chars) - 1) ];
    }

    return $password;
}

方法二

动生成6位数字、字母 混合密码

 代码如下 复制代码
$str = "0123456789abcdefghijklmnopqrstuvwxyz";   //   输出字符集 
$n = 6;   //   输出串长度 
$len = strlen($str)-1;
for($j=0 ; $jfor($i=0 ; $i    $s .=  $str[rand(0,$len)]; 
}
echo $s . "
";
$s = "";
}
?>
自动生成数字、字母、符号的密码
      $a = "12345678";
      $b = "abcdefghijklmnopqistuvwxyz";
      $s = substr(str_shuffle($a), 0, 2);
      $e = substr(str_shuffle($b), 0, 2);
      echo $s . substr(str_shuffle("!@#$%^&*"), 0, 2) . $e;
?>

方法三

 代码如下 复制代码

function create_password($pw_length = 8)
{
    $randpwd = '';
    for ($i = 0; $i     {
        $randpwd .= chr(mt_rand(33, 126));
    }
    return $randpwd;
}

// 调用该函数,传递长度参数$pw_length = 6
echo create_password(6);


方法三

 代码如下 复制代码

function getmicrotime()
{
    list($usec, $sec) = explode(" ",microtime());
    return ((float)$usec + (float)$sec);
}
 
// 记录开始时间
$time_start = getmicrotime();
   
// 这里放要执行的php代码,如:
// echo create_password(6);
 
// 记录结束时间
$time_end = getmicrotime();
$time = $time_end - $time_start;

 // 输出运行总时间
echo "执行时间 $time seconds";
?>



本文地址:

转载随意,但请附上文章地址:-)

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment