Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
d6c4b83f
Commit
d6c4b83f
authored
12 years ago
by
Lukas Reschke
Browse files
Options
Downloads
Patches
Plain Diff
Fallback to /dev/random if openssl_random_pseudo_bytes not available
parent
99cd922b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/util.php
+14
-6
14 additions, 6 deletions
lib/util.php
with
14 additions
and
6 deletions
lib/util.php
+
14
−
6
View file @
d6c4b83f
...
...
@@ -556,12 +556,13 @@ class OC_Util {
}
/*
* @brief Generates random bytes with "openssl_random_pseudo_bytes" with a fallback for systems without openssl
* Inspired by gorgo on php.net
* @param Int with the length of the random
* @return String with the random bytes
* @brief Generates a cryptographical secure pseudorandom string
* @param Int with the length of the random string
* @return String
*/
public
static
function
generate_random_bytes
(
$length
=
30
)
{
// Try to use openssl_random_pseudo_bytes
if
(
function_exists
(
'openssl_random_pseudo_bytes'
))
{
$pseudo_byte
=
bin2hex
(
openssl_random_pseudo_bytes
(
$length
,
$strong
));
if
(
$strong
==
TRUE
)
{
...
...
@@ -569,9 +570,16 @@ class OC_Util {
}
}
// fallback to mt_rand()
// Try to use /dev/random
$fp
=
@
file_get_contents
(
'/dev/random'
,
false
,
null
,
0
,
$length
);
if
(
$fp
!==
FALSE
)
{
$string
=
substr
(
bin2hex
(
$fp
),
0
,
$length
);
return
$string
;
}
// Fallback to mt_rand()
$characters
=
'0123456789'
;
$characters
.
=
'
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz'
;
$characters
.
=
'abcdefghijklmnopqrstuvwxyz'
;
$charactersLength
=
strlen
(
$characters
)
-
1
;
$pseudo_byte
=
""
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment