JUserHelper/genRandomPassword: Difference between revisions
From Joomla! Documentation
New page: ===Description===
Generate a random password
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]... |
m clean up |
||
| Line 2: | Line 2: | ||
Generate a random password | Generate a random password | ||
{{Description:JUserHelper/genRandomPassword}} | |||
{{subst:Description:JUserHelper/genRandomPassword}} | |||
===Syntax=== | ===Syntax=== | ||
| Line 51: | Line 49: | ||
</source> | </source> | ||
{{subst:SeeAlso:JUserHelper/genRandomPassword}} | |||
{{SeeAlso:JUserHelper/genRandomPassword}} | |||
===Examples=== | ===Examples=== | ||
Revision as of 14:36, 24 March 2017
Description
Generate a random password
{{subst:Description:JUserHelper/genRandomPassword}}
Syntax
static genRandomPassword($length=8)
| Parameter Name | Default Value | Description |
|---|---|---|
| $length | 8 | $length Length of the password to generate |
Returns
string Random Password
Defined in
libraries/joomla/user/helper.php
Importing
jimport( 'joomla.user.helper' );
Source Body
public static function genRandomPassword($length = 8)
{
$salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$len = strlen($salt);
$makepass = '';
$stat = @stat(__FILE__);
if (empty($stat) || !is_array($stat)) $stat = array(php_uname());
mt_srand(crc32(microtime() . implode('|', $stat)));
for ($i = 0; $i < $length; $i ++) {
$makepass .= $salt[mt_rand(0, $len -1)];
}
return $makepass;
}
{{subst:SeeAlso:JUserHelper/genRandomPassword}}
Examples
<CodeExamplesForm />