Actions

API16

JUserHelper/genRandomPassword

From Joomla! Documentation

< API16:JUserHelper
Revision as of 17:36, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Generate a random password

[Edit Descripton]

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

[Edit See Also] SeeAlso:JUserHelper/genRandomPassword

Examples

<CodeExamplesForm />