API16

JUserHelper/genRandomPassword: Difference between revisions

From Joomla! Documentation

m clean up
m preparing for archive only
 
Line 4: Line 4:




{{subst:Description:JUserHelper/genRandomPassword}}
 


===Syntax===
===Syntax===
Line 50: Line 50:




{{subst:SeeAlso:JUserHelper/genRandomPassword}}
 


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=genRandomPassword
  category=genRandomPassword
  category=JUserHelper
  category=JUserHelper
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*
  format= ,,,
  format= ,,,
</dpl>
</dpl>

Latest revision as of 02:16, 25 March 2017

Description

Generate a random password



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;
}



Examples

Code Examples