#1141 Add TOTP key field to database and PlayerAuth

- Add new field for storing TOTP key
- Implement data source methods for manipulation of its value
This commit is contained in:
ljacqu
2018-03-05 19:50:58 +01:00
parent 930f5609bf
commit 9954c82cb6
10 changed files with 126 additions and 2 deletions
@@ -26,6 +26,7 @@ public class PlayerAuth {
/** The player's name in the correct casing, e.g. "Xephi". */
private String realName;
private HashedPassword password;
private String totpKey;
private String email;
private String lastIp;
private int groupId;
@@ -160,6 +161,10 @@ public class PlayerAuth {
this.registrationDate = registrationDate;
}
public String getTotpKey() {
return totpKey;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof PlayerAuth)) {
@@ -195,6 +200,7 @@ public class PlayerAuth {
private String name;
private String realName;
private HashedPassword password;
private String totpKey;
private String lastIp;
private String email;
private int groupId = -1;
@@ -219,6 +225,7 @@ public class PlayerAuth {
auth.nickname = checkNotNull(name).toLowerCase();
auth.realName = firstNonNull(realName, "Player");
auth.password = firstNonNull(password, new HashedPassword(""));
auth.totpKey = totpKey;
auth.email = DB_EMAIL_DEFAULT.equals(email) ? null : email;
auth.lastIp = lastIp; // Don't check against default value 127.0.0.1 as it may be a legit value
auth.groupId = groupId;
@@ -258,6 +265,11 @@ public class PlayerAuth {
return password(new HashedPassword(hash, salt));
}
public Builder totpKey(String totpKey) {
this.totpKey = totpKey;
return this;
}
public Builder lastIp(String lastIp) {
this.lastIp = lastIp;
return this;