Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
eduGAIN Access Check - Account manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
edugain
eduGAIN Access Check - Account manager
Commits
74544bfe
Commit
74544bfe
authored
7 years ago
by
Guillaume ROUSSE
Browse files
Options
Downloads
Patches
Plain Diff
rewrite generate_token similarily to generate_password
parent
3faba161
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/AccountManager/Tools.pm
+16
-9
16 additions, 9 deletions
lib/AccountManager/Tools.pm
t/tools.t
+13
-9
13 additions, 9 deletions
t/tools.t
with
29 additions
and
18 deletions
lib/AccountManager/Tools.pm
+
16
−
9
View file @
74544bfe
...
...
@@ -4,7 +4,6 @@ use strict;
use
warnings
;
use
Digest::
SHA
;
use
Digest::
MD5
;
use
Encode
;
use
English
qw(-no_match_vars)
;
use
List::
Util
qw(shuffle)
;
...
...
@@ -48,10 +47,10 @@ sub sha256_hash {
return
Digest::SHA::
sha256_base64
(
$s
);
}
# This function generates a random password
sub
generate_password
{
my
$size
=
10
;
my
(
$size
)
=
@_
;
# define alphabet
my
@uppers
=
('
A
'
..
'
N
',
'
P
'
..
'
Z
');
my
@lowers
=
('
a
'
..
'
k
',
'
m
'
..
'
z
');
my
@punctuations
=
('
:
',
'
!
',
'
?
',
'
&
',
'
$
',
'
=
',
'
-
',
'
#
');
...
...
@@ -74,13 +73,21 @@ sub generate_password {
return
join
('',
shuffle
(
@chars
));
}
# ID is based on time + PID
sub
generate_token
{
my
(
$salt
,
$size
)
=
@_
;
$salt
=
$PID
unless
$salt
;
$size
=
20
unless
$size
;
sub
generate_secret
{
my
(
$size
)
=
@_
;
return
substr
(
Digest::MD5::
md5_hex
(
time
.
$salt
),
-
1
*
$size
);
# define alphabet
my
@lowers
=
('
a
'
..
'
k
',
'
m
'
..
'
z
');
my
@numerics
=
('
0
'
..
'
9
');
my
@all
=
(
@lowers
,
@numerics
);
# fill characters list
my
@chars
;
for
my
$i
(
1
..
$size
)
{
push
(
@chars
,
$all
[
rand
@all
]);
}
return
join
('',
shuffle
(
@chars
));
}
## Updates simpleSamlPhp authsources.php configuration file
...
...
This diff is collapsed.
Click to expand it.
t/tools.t
+
13
−
9
View file @
74544bfe
...
...
@@ -8,16 +8,20 @@ use Test::More;
use
AccountManager::
Tools
;
plan
tests
=>
4
;
plan
tests
=>
5
;
my
$key
=
AccountManager::Tools::
generate_
token
(
undef
,
10
);
my
$
secret
=
AccountManager::Tools::
generate_password
();
my
$key
=
AccountManager::Tools::
generate_
secret
(
10
);
my
$
password
=
AccountManager::Tools::
generate_password
(
10
);
ok
(
$key
ne
$secret
,
'
key and secret are random strings
');
ok
(
length
(
$key
)
==
length
(
$secret
),
'
key and secret have same size
');
ok
(
length
(
$password
)
==
10
,
'
password has expected size
');
ok
(
length
(
$key
)
==
10
,
'
key has expected size
');
ok
(
$key
ne
$password
,
'
key and passwords are random strings
');
my
$encrypted_password
=
AccountManager::Tools::
encrypt
(
$password
,
$key
);
ok
(
$encrypted_password
ne
$password
,
'
encrypted password differs from password
');
my
$decrypted_password
=
AccountManager::Tools::
decrypt
(
$encrypted_password
,
$key
);
ok
(
$decrypted_password
eq
$password
,
'
decrypted password matches password
');
my
$encrypted_secret
=
AccountManager::Tools::
encrypt
(
$secret
,
$key
);
ok
(
$encrypted_secret
ne
$secret
,
'
crypted_secret and secret are differents
');
my
$decrypted_secret
=
AccountManager::Tools::
decrypt
(
$encrypted_secret
,
$key
);
ok
(
$decrypted_secret
eq
$secret
,
'
decrypted_secret and secret are equals
');
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