Skip to content
Snippets Groups Projects
Commit 7dc6c401 authored by Simon's avatar Simon
Browse files

Readded PswdHashing and saltgeneration

parent 4cc1d3f6
No related branches found
No related tags found
No related merge requests found
......@@ -184,7 +184,8 @@ public class UserDAO {
* @return a random salt
*/
public byte[] generateSalt() {
return null;
SecureRandom random = new SecureRandom();
return random.generateSeed(16);
}
/**
......@@ -194,9 +195,22 @@ public class UserDAO {
* @return hashedPassword, null if unsuccessful
*/
public String hashPassword(String password, byte[] salt) {
try {
MessageDigest md = java.security.MessageDigest.getInstance("SHA-256");
md.update(salt);
byte[] digest = (md.digest(password.getBytes()));
StringBuilder stringBuilder = new StringBuilder();
for(int i = 0; i < digest.length; i++){
stringBuilder.append(Integer.toString((digest[i] & 0xff) + 0x100,
16).substring(1));
}
return stringBuilder.toString();
} catch (Exception e) {
return null;
}
}
/**
* Edits the users username or password
* @param userId userId as int
......
File deleted
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment