Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
devops-workshop
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
Henning Sara Strandå
devops-workshop
Commits
6521f172
Commit
6521f172
authored
2 years ago
by
Henning Sara Strandå
Browse files
Options
Downloads
Plain Diff
Merge branch 'feat/password_hashing' into 'master'
Feat/password hashing See merge request
!1
parents
75a24563
342a4373
No related branches found
No related tags found
1 merge request
!1
Feat/password hashing
Pipeline
#202959
passed
2 years ago
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/dao/UserDAO.java
+20
-1
20 additions, 1 deletion
src/main/java/dao/UserDAO.java
with
20 additions
and
1 deletion
src/main/java/dao/UserDAO.java
+
20
−
1
View file @
6521f172
...
...
@@ -2,7 +2,9 @@ package dao;
import
data.User
;
import
java.io.UnsupportedEncodingException
;
import
java.nio.charset.StandardCharsets
;
import
java.security.DigestException
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.SecureRandom
;
...
...
@@ -197,7 +199,24 @@ public class UserDAO {
* @return hashedPassword, null if unsuccessful
*/
public
String
hashPassword
(
String
password
,
byte
[]
salt
)
{
return
null
;
MessageDigest
md
;
byte
[]
encodedHash
;
try
{
byte
[]
bytesOfPassword
=
password
.
getBytes
(
StandardCharsets
.
UTF_8
);
md
=
MessageDigest
.
getInstance
(
"SHA-512"
);
md
.
update
(
salt
);
encodedHash
=
md
.
digest
(
bytesOfPassword
);
}
catch
(
NoSuchAlgorithmException
e
)
{
throw
new
RuntimeException
(
e
);
}
StringBuilder
stringBuilder
=
new
StringBuilder
();
for
(
byte
b
:
encodedHash
)
{
stringBuilder
.
append
(
Integer
.
toString
((
b
&
0xff
)
+
0x100
,
16
).
substring
(
1
));
}
return
stringBuilder
.
toString
();
}
/**
...
...
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