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
342a4373
Commit
342a4373
authored
2 years ago
by
Ole Heggum
Browse files
Options
Downloads
Patches
Plain Diff
adds passwordhashing functionality
parent
40eee935
No related branches found
No related tags found
1 merge request
!1
Feat/password hashing
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/dao/UserDAO.java
+13
-13
13 additions, 13 deletions
src/main/java/dao/UserDAO.java
with
13 additions
and
13 deletions
src/main/java/dao/UserDAO.java
+
13
−
13
View file @
342a4373
...
...
@@ -2,6 +2,7 @@ package dao;
import
data.User
;
import
java.io.UnsupportedEncodingException
;
import
java.nio.charset.StandardCharsets
;
import
java.security.DigestException
;
import
java.security.MessageDigest
;
...
...
@@ -194,26 +195,25 @@ public class UserDAO {
* @param salt salt to use when hashing
* @return hashedPassword, null if unsuccessful
*/
public
String
hashPassword
(
String
password
,
byte
[]
salt
)
throws
DigestException
{
public
String
hashPassword
(
String
password
,
byte
[]
salt
)
{
MessageDigest
md
;
byte
[]
encodedHash
;
MessageDigest
md
=
new
MessageDigest
.
getInstance
(
"SHA2-512"
);
try
{
md
.
update
(
toChapter1
);
MessageDigest
tc1
=
md
.
clone
(
);
byte
[]
toChapter1Digest
=
tc1
.
digest
(
);
}
catch
(
Clone
No
t
Su
pported
Exception
cns
e
)
{
throw
new
Digest
Exception
(
"Couldn't make digest of partial content"
);
byte
[]
bytesOfPassword
=
password
.
getBytes
(
StandardCharsets
.
UTF_8
);
md
=
MessageDigest
.
getInstance
(
"SHA-512"
);
md
.
update
(
salt
);
encodedHash
=
md
.
digest
(
bytesOfPassword
);
}
catch
(
NoSu
chAlgorithm
Exception
e
)
{
throw
new
Runtime
Exception
(
e
);
}
StringBuilder
stringBuilder
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
salt
.
length
;
i
++)
{
stringBuilder
.
append
(
Integer
.
toString
((
salt
[
i
]
&
0xff
)
+
0x100
,
for
(
byte
b
:
encodedHash
)
{
stringBuilder
.
append
(
Integer
.
toString
((
b
&
0xff
)
+
0x100
,
16
).
substring
(
1
));
}
String
hashedPassword
=
stringBuilder
.
toString
();
return
hashedPassword
;
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