Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
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
Yeray Santana Hualde
syncEnrollments
Commits
6e120eee
Commit
6e120eee
authored
Jan 17, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleaning up the hash class.
parent
86bbb5f1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
24 deletions
+16
-24
hash.php
laravel/hash.php
+16
-24
No files found.
laravel/hash.php
View file @
6e120eee
...
@@ -21,7 +21,22 @@ class Hash {
...
@@ -21,7 +21,22 @@ class Hash {
{
{
$work
=
str_pad
(
$rounds
,
2
,
'0'
,
STR_PAD_LEFT
);
$work
=
str_pad
(
$rounds
,
2
,
'0'
,
STR_PAD_LEFT
);
return
crypt
(
$value
,
'$2a$'
.
$work
.
'$'
.
static
::
salt
());
// Bcrypt expects the salt to be 22 base64 encoded characters including
// dots and slashes. We will get rid of the plus signs included in the
// base64 data and replace them with dots. OpenSSL will be used if it
// is available, otherwise we will use the Str::random method.
if
(
function_exists
(
'openssl_random_pseudo_bytes'
))
{
$salt
=
openssl_random_pseudo_bytes
(
16
);
}
else
{
$salt
=
Str
::
random
(
40
);
}
$salt
=
substr
(
strtr
(
base64_encode
(
$salt
),
'+'
,
'.'
),
0
,
22
);
return
crypt
(
$value
,
'$2a$'
.
$work
.
'$'
.
$salt
);
}
}
/**
/**
...
@@ -36,27 +51,4 @@ class Hash {
...
@@ -36,27 +51,4 @@ class Hash {
return
crypt
(
$value
,
$hash
)
===
$hash
;
return
crypt
(
$value
,
$hash
)
===
$hash
;
}
}
/**
* Get a salt for use during Bcrypt hashing.
*
* @return string
*/
protected
static
function
salt
()
{
// Bcrypt expects the salt to be 22 base64 encoded characters including
// dots and slashes. We will get rid of the plus signs included in the
// base64 data and replace them with dots. OpenSSL will be used if it
// is available, otherwise we will use the Str::random method.
if
(
function_exists
(
'openssl_random_pseudo_bytes'
))
{
$bytes
=
openssl_random_pseudo_bytes
(
16
);
return
substr
(
strtr
(
base64_encode
(
$bytes
),
'+'
,
'.'
),
0
,
22
);
}
$salt
=
str_replace
(
'+'
,
'.'
,
base64_encode
(
Str
::
random
(
40
)));
return
substr
(
$salt
,
0
,
22
);
}
}
}
\ No newline at end of file
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