Add read-only clientVersion property to LoginCredentials

This is just a regular string that can be used to confirm the
compatibility between client and server.
This commit is contained in:
Kai S. K. Engelbart 2020-06-19 15:56:45 +02:00
parent 13b4626737
commit bb6360d2a7

View File

@ -20,22 +20,25 @@ public class LoginCredentials implements Serializable {
private final String identifier; private final String identifier;
private final byte[] passwordHash; private final byte[] passwordHash;
private final boolean registration; private final boolean registration;
private final String clientVersion;
private static final long serialVersionUID = -7395245059059523314L; private static final long serialVersionUID = 1;
/** /**
* Creates an instance of {@link LoginCredentials} for a new {@link User}. * Creates an instance of {@link LoginCredentials} for a new {@link User}.
* *
* @param identifier the identifier of the user * @param identifier the identifier 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 * @param registration signifies that these credentials are used for user
* registration instead of user login * registration instead of user login
* @param clientVersion the version of the client sending these credentials
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
*/ */
public LoginCredentials(String identifier, char[] password, boolean registration) { public LoginCredentials(String identifier, char[] password, boolean registration, String clientVersion) {
this.identifier = identifier; this.identifier = identifier;
passwordHash = getSha256(toByteArray(password)); passwordHash = getSha256(toByteArray(password));
this.registration = registration; this.registration = registration;
this.clientVersion = clientVersion;
} }
private byte[] getSha256(byte[] input) { private byte[] getSha256(byte[] input) {
@ -84,4 +87,10 @@ public class LoginCredentials implements Serializable {
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
*/ */
public boolean isRegistration() { return registration; } public boolean isRegistration() { return registration; }
/**
* @return the version of the client sending these credentials
* @since Envoy Common v0.1-beta
*/
public String getClientVersion() { return clientVersion; }
} }