From 6d614580ef140a46813c0bccacf02a164e4c1c06 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 8 Feb 2020 09:47:59 +0100 Subject: [PATCH] Removed ID artifact from LoginCredentials --- .../java/envoy/data/LoginCredentials.java | 38 ++++--------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/src/main/java/envoy/data/LoginCredentials.java b/src/main/java/envoy/data/LoginCredentials.java index e9b9b1c..fbcb398 100644 --- a/src/main/java/envoy/data/LoginCredentials.java +++ b/src/main/java/envoy/data/LoginCredentials.java @@ -18,7 +18,6 @@ import java.util.Formatter; public class LoginCredentials implements Serializable { private final String identifier; - private final long id; private final byte[] passwordHash; private final boolean registration; @@ -27,33 +26,17 @@ public class LoginCredentials implements Serializable { /** * Creates an instance of {@link LoginCredentials} for a new {@link User}. * - * @param identifier the identifier of the user - * @param password the password of the user (will be converted to a hash) + * @param identifier the identifier of the user + * @param password the password of the user (will be converted to a hash) + * @param registration if true, the user registers himself with this + * {@link LoginCredentials} * @throws NoSuchAlgorithmException if the algorithm used is unknown * @since Envoy Common v0.2-alpha */ - public LoginCredentials(String identifier, char[] password) throws NoSuchAlgorithmException { + public LoginCredentials(String identifier, char[] password, boolean registration) throws NoSuchAlgorithmException { this.identifier = identifier; - this.id = -1; passwordHash = getSha256(toByteArray(password)); - this.registration = true; - } - - /** - * Creates an instance of {@link LoginCredentials} for an {@link User} who - * already registered himself (knows his id). - * - * @param id the id of the user - * @param password the password of the user (will be converted to a hash) - * @throws NoSuchAlgorithmException if the algorithm used is unknown - * @since Envoy Common v0.2-alpha - */ - public LoginCredentials(long id, char[] password) throws NoSuchAlgorithmException { - if (id <= 0) throw new IllegalArgumentException("Entered an illegal Id. Ids can not be below 1. Id was " + id); - this.id = id; - passwordHash = getSha256(toByteArray(password)); - this.registration = false; - this.identifier = ""; + this.registration = registration; } private byte[] getSha256(byte[] input) throws NoSuchAlgorithmException { return MessageDigest.getInstance("SHA-256").digest(input); } @@ -70,8 +53,7 @@ public class LoginCredentials implements Serializable { @Override public String toString() { try (Formatter form = new Formatter()) { - if (registration) form.format("LoginCredentials[identifier=%s,passwordHash=", identifier); - else form.format("LoginCredentials[id=%d,passwordHash=", id); + form.format("LoginCredentials[identifier=%s,passwordHash=", identifier); for (byte element : passwordHash) form.format("%02x", element); return form.format(",registration=%b]", registration).toString(); @@ -90,12 +72,6 @@ public class LoginCredentials implements Serializable { */ public byte[] getPasswordHash() { return passwordHash; } - /** - * @return the id of the underlying user - * @since Envoy Common v0.2-alpha - */ - public long getId() { return id; } - /** * @return {@code true} if these credentials are used for user registration * instead of user login