Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp
Commits
ee81462b
Unverified
Commit
ee81462b
authored
4 years ago
by
Tim van Dijen
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add flexibility to Crypto::pwHash; allow algorithm to be set
parent
abf91c3e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/SimpleSAML/Utils/Crypto.php
+8
-6
8 additions, 6 deletions
lib/SimpleSAML/Utils/Crypto.php
with
8 additions
and
6 deletions
lib/SimpleSAML/Utils/Crypto.php
+
8
−
6
View file @
ee81462b
...
...
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace
SimpleSAML\Utils
;
use
InvalidArgumentException
;
use
SimpleSAML\Configuration
;
use
SimpleSAML\Error
;
use
Webmozart\Assert\Assert
;
...
...
@@ -33,7 +34,7 @@ class Crypto
/** @var int $len */
$len
=
mb_strlen
(
$ciphertext
,
'8bit'
);
if
(
$len
<
48
)
{
throw
new
\
InvalidArgumentException
(
throw
new
InvalidArgumentException
(
'Input parameter "$ciphertext" must be a string with more than 48 characters.'
);
}
...
...
@@ -300,11 +301,11 @@ class Crypto
$last
=
count
(
$lines
)
-
1
;
if
(
strpos
(
$lines
[
0
],
$begin
)
!==
0
)
{
throw
new
\
InvalidArgumentException
(
"pem2der: input is not encoded in PEM format."
);
throw
new
InvalidArgumentException
(
"pem2der: input is not encoded in PEM format."
);
}
unset
(
$lines
[
0
]);
if
(
strpos
(
$lines
[
$last
],
$end
)
!==
0
)
{
throw
new
\
InvalidArgumentException
(
"pem2der: input is not encoded in PEM format."
);
throw
new
InvalidArgumentException
(
"pem2der: input is not encoded in PEM format."
);
}
unset
(
$lines
[
$last
]);
...
...
@@ -316,6 +317,7 @@ class Crypto
* This function hashes a password with a given algorithm.
*
* @param string $password The password to hash.
* @param int $algorithm The algorithm to use. Defaults to the system default
*
* @return string The hashed password.
* @throws \InvalidArgumentException If the input parameter is not a string.
...
...
@@ -326,10 +328,10 @@ class Crypto
* @author Dyonisius Visser, TERENA <visser@terena.org>
* @author Jaime Perez, UNINETT AS <jaime.perez@uninett.no>
*/
public
static
function
pwHash
(
string
$password
):
string
public
static
function
pwHash
(
string
$password
,
int
$algorithm
=
PASSWORD_DEFAULT
):
string
{
if
(
!
is_string
(
$hash
=
password_hash
(
$password
,
PASSWORD_DEFAULT
)))
{
throw
new
\
InvalidArgumentException
(
'Error while hashing password.'
);
if
(
!
is_string
(
$hash
=
password_hash
(
$password
,
$algorithm
)))
{
throw
new
InvalidArgumentException
(
'Error while hashing password.'
);
}
return
$hash
;
}
...
...
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