Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
54d0b02e
Commit
54d0b02e
authored
Jan 19, 2007
by
Nigel McNie
Committed by
Nigel McNie
Jan 19, 2007
Browse files
Allow the get_random_key function to have an optional length passed to it
parent
d91e5de0
Changes
1
Hide whitespace changes
Inline
Side-by-side
htdocs/lib/mahara.php
View file @
54d0b02e
...
...
@@ -777,9 +777,13 @@ function format_date($date, $formatkey='strftimedatetime') {
/**
* Returns a random string suitable for registration/change password requests
*
* @param int $length The length of the key to return
* @return string
*/
function
get_random_key
()
{
function
get_random_key
(
$length
=
16
)
{
if
(
$length
<
1
)
{
throw
new
IllegalArgumentException
(
'Length must be a positive number'
);
}
$pool
=
array_merge
(
range
(
'A'
,
'Z'
),
range
(
'a'
,
'z'
),
...
...
@@ -787,7 +791,7 @@ function get_random_key() {
);
shuffle
(
$pool
);
$result
=
''
;
for
(
$i
=
0
;
$i
<
16
;
$i
++
)
{
for
(
$i
=
0
;
$i
<
$length
;
$i
++
)
{
$result
.
=
$pool
[
$i
];
}
return
$result
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment