Skip to content
Snippets Groups Projects
Commit 342a4373 authored by Ole Heggum's avatar Ole Heggum
Browse files

adds passwordhashing functionality

parent 40eee935
No related branches found
No related tags found
1 merge request!1Feat/password hashing
......@@ -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 (CloneNotSupportedException cnse) {
throw new DigestException("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 (NoSuchAlgorithmException e) {
throw new RuntimeException(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();
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment