Skip to content
Snippets Groups Projects
Commit 6521f172 authored by Henning Sara Strandå's avatar Henning Sara Strandå
Browse files

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!1Feat/password hashing
Pipeline #202959 passed
......@@ -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();
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment