生成随机密码或盐。

Generate keys and salts using secure CSPRNG

$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|';
//字符打乱
$chars = str_shuffle($chars);
$max = strlen($chars) - 1;
for ( $i = 0; $i < 8; $i++ ) {
	$key = '';
	for ( $j = 0; $j < 64; $j++ ) {
		//如果是php mt_rand函数可换成random_int
		$key .= substr( $chars, mt_rand( 0, $max ), 1 );
	}
	$secret_keys[] = $key;
}

//输出
print_r($secret_keys);

//from http://www.cnblogs.com/osfipin/

  输出结果演示:

php 随机密码和盐 来自wordpress

如果不是php7也想使用random_int(可以产生更高质量的随机数)函数,可以使用 Paragon Initiative 公司的 random_compat 库。

相关文章:

  • 2022-12-23
  • 2021-09-28
  • 2021-05-20
  • 2021-10-20
  • 2021-10-17
  • 2022-12-23
  • 2021-05-21
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-16
  • 2022-12-23
  • 2022-01-25
  • 2021-06-09
  • 2021-08-29
相关资源
相似解决方案