Added boolean registration to LoginCredentials

This commit is contained in:
Kai S. K. Engelbart 2020-01-18 10:27:29 +01:00
parent 19bbaf7d7a
commit e5c67b859b
4 changed files with 32 additions and 10 deletions

View File

@ -24,5 +24,10 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/> <attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>

View File

@ -1,5 +1,6 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
encoding//src/main/java=UTF-8 encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8 encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8 encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8 encoding/<project>=UTF-8

View File

@ -2,11 +2,15 @@
<wb-module deploy-name="envoy-common"> <wb-module deploy-name="envoy-common">
<wb-resource deploy-path="/" source-path="/src/main/java"/> <wb-resource deploy-path="/" source-path="/src/main/java"/>
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
@ -14,4 +18,5 @@
</project-modules> </project-modules>

View File

@ -19,6 +19,7 @@ public class LoginCredentials implements Serializable {
private final String name; private final String name;
private final byte[] passwordHash; private final byte[] passwordHash;
private final boolean registration;
private static final long serialVersionUID = -7395245059059523314L; private static final long serialVersionUID = -7395245059059523314L;
@ -27,12 +28,15 @@ public class LoginCredentials implements Serializable {
* *
* @param name the name of the user * @param name the name of the user
* @param password the password of the user (will be converted to a hash) * @param password the password of the user (will be converted to a hash)
* @param registration signifies that these credentials are used for user
* registration instead of user login
* @throws NoSuchAlgorithmException if the algorithm used is unknown * @throws NoSuchAlgorithmException if the algorithm used is unknown
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
*/ */
public LoginCredentials(String name, char[] password) throws NoSuchAlgorithmException { public LoginCredentials(String name, char[] password, boolean registration) throws NoSuchAlgorithmException {
this.name = name; this.name = name;
passwordHash = getSha256(toByteArray(password)); passwordHash = getSha256(toByteArray(password));
this.registration = registration;
} }
private byte[] getSha256(byte[] input) throws NoSuchAlgorithmException { return MessageDigest.getInstance("SHA-256").digest(input); } private byte[] getSha256(byte[] input) throws NoSuchAlgorithmException { return MessageDigest.getInstance("SHA-256").digest(input); }
@ -52,7 +56,7 @@ public class LoginCredentials implements Serializable {
form.format("LoginCredentials[name=%s,passwordHash=", name); form.format("LoginCredentials[name=%s,passwordHash=", name);
for (byte element : passwordHash) for (byte element : passwordHash)
form.format("%02x", element); form.format("%02x", element);
return form.format("]").toString(); return form.format(",registration=%b]", registration).toString();
} }
} }
@ -67,4 +71,11 @@ public class LoginCredentials implements Serializable {
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
*/ */
public byte[] getPasswordHash() { return passwordHash; } public byte[] getPasswordHash() { return passwordHash; }
/**
* @return {@code true} if these credentials are used for user registration
* instead of user login
* @since Envoy Common v0.2-alpha
*/
public boolean isRegistration() { return registration; }
} }