CCM NG: Replaced string constant for UTF-8 with java.nio.charset.StandardCharsets.UTF_8
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3514 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
40f9b8d79d
commit
bae3e911a7
|
|
@ -26,7 +26,6 @@ package org.libreccm.core;
|
|||
public final class CoreConstants {
|
||||
|
||||
public static final String CORE_XML_NS = "http://core.libreccm.org";
|
||||
public static final String UTF8 = "UTF-8";
|
||||
|
||||
private CoreConstants() {
|
||||
//Nothing
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import static org.libreccm.core.CoreConstants.*;
|
|||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Random;
|
||||
|
|
@ -73,10 +74,9 @@ public class UserManager {
|
|||
* @param password The new password.
|
||||
*/
|
||||
public void updatePassword(final User user, final String password) {
|
||||
|
||||
try {
|
||||
final Random random = new Random(System.currentTimeMillis());
|
||||
final byte[] passwordBytes = password.getBytes(UTF8);
|
||||
final byte[] passwordBytes = password.getBytes(
|
||||
StandardCharsets.UTF_8);
|
||||
final byte[] salt = new byte[getSaltLength()];
|
||||
random.nextBytes(salt);
|
||||
|
||||
|
|
@ -89,11 +89,6 @@ public class UserManager {
|
|||
user.setPassword(hashedPassword);
|
||||
user.setSalt(saltStr);
|
||||
userRepository.save(user);
|
||||
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
throw new PasswordHashingFailedException(
|
||||
"UTF-8 charset is not supported.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -109,18 +104,14 @@ public class UserManager {
|
|||
final String password) {
|
||||
final Base64 base64 = new Base64();
|
||||
|
||||
try {
|
||||
final byte[] hashed = generateHash(
|
||||
password.getBytes(UTF8), base64.decode(user.getSalt()));
|
||||
password.getBytes(StandardCharsets.UTF_8),
|
||||
base64.decode(user.getSalt()));
|
||||
|
||||
final String hashedPassword = base64.encodeAsString(hashed);
|
||||
|
||||
return hashedPassword.equals(user.getPassword());
|
||||
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
throw new PasswordHashingFailedException(
|
||||
"Failed to generate hash of password", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean verifyPasswordForScreenname(final String screenname,
|
||||
|
|
@ -139,7 +130,7 @@ public class UserManager {
|
|||
|
||||
public boolean verifyPasswordForEmail(final String emailAddress,
|
||||
final String password)
|
||||
throws UserNotFoundException{
|
||||
throws UserNotFoundException {
|
||||
|
||||
final User user = userRepository.findByEmailAddress(emailAddress);
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ import org.libreccm.tests.categories.IntegrationTest;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
|
|
@ -168,7 +169,8 @@ public class UserManagerTest {
|
|||
|
||||
final Base64 base64 = new Base64();
|
||||
final User user = entityManager.find(User.class, -10L);
|
||||
final byte[] passwordBytes = newPassword.getBytes(UTF8);
|
||||
final byte[] passwordBytes = newPassword.getBytes(
|
||||
StandardCharsets.UTF_8);
|
||||
final String salt = user.getSalt();
|
||||
final byte[] saltBytes = base64.decode(salt);
|
||||
|
||||
|
|
@ -203,7 +205,6 @@ public class UserManagerTest {
|
|||
final User user = userRepository.findById(-10L);
|
||||
|
||||
//userManager.updatePassword(user, "foobar");
|
||||
|
||||
final boolean result = userManager.verifyPasswordForUser(user, "foobar");
|
||||
|
||||
assertThat(result, is(true));
|
||||
|
|
|
|||
Loading…
Reference in New Issue