Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
cf47a71d
Commit
cf47a71d
authored
Jun 02, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes issue #478: Improved the generation of secret key
parent
21160338
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
3 deletions
+18
-3
SecurityHelper.php
framework/yii/helpers/base/SecurityHelper.php
+18
-3
No files found.
framework/yii/helpers/base/SecurityHelper.php
View file @
cf47a71d
...
...
@@ -131,15 +131,30 @@ class SecurityHelper
$keys
=
is_file
(
$keyFile
)
?
require
(
$keyFile
)
:
array
();
}
if
(
!
isset
(
$keys
[
$name
]))
{
// generate a 32-char random key
$chars
=
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
;
$keys
[
$name
]
=
substr
(
str_shuffle
(
str_repeat
(
$chars
,
5
)),
0
,
$length
);
$keys
[
$name
]
=
static
::
generateRandomKey
(
$length
);
file_put_contents
(
$keyFile
,
"<?php
\n
return "
.
var_export
(
$keys
,
true
)
.
";
\n
"
);
}
return
$keys
[
$name
];
}
/**
* Generates a random key.
* @param integer $length the length of the key that should be generated
* @return string the generated random key
*/
public
static
function
generateRandomKey
(
$length
=
32
)
{
if
(
function_exists
(
'openssl_random_pseudo_bytes'
))
{
$key
=
base64_encode
(
openssl_random_pseudo_bytes
(
$length
,
$strong
));
if
(
$strong
)
{
return
substr
(
$key
,
0
,
$length
);
}
}
$chars
=
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
;
return
substr
(
str_shuffle
(
str_repeat
(
$chars
,
5
)),
0
,
$length
);
}
/**
* Opens the mcrypt module.
* @return resource the mcrypt module handle.
* @throws InvalidConfigException if mcrypt extension is not installed
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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