aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/juick/server/UserQueries.java13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/main/java/com/juick/server/UserQueries.java b/src/main/java/com/juick/server/UserQueries.java
index 1bab7c7f5..af7997ea4 100644
--- a/src/main/java/com/juick/server/UserQueries.java
+++ b/src/main/java/com/juick/server/UserQueries.java
@@ -184,19 +184,18 @@ public class UserQueries {
}
public static String getHashByUID(JdbcTemplate sql, int uid) {
- String hash = sql.queryForObject("SELECT hash FROM logins WHERE user_id=?", String.class, uid);
-
- if (hash == null) {
- hash = generateHash(16);
- final String finalHash = hash;
+ try {
+ return sql.queryForObject("SELECT hash FROM logins WHERE user_id=?", String.class, uid);
+ } catch (EmptyResultDataAccessException e){
+ String hash = generateHash(16);
sql.update(con -> {
PreparedStatement stmt = con.prepareStatement("INSERT INTO logins(user_id,hash) VALUES (?,?)");
stmt.setInt(1, uid);
- stmt.setString(2, finalHash);
+ stmt.setString(2, hash);
return stmt;
});
+ return hash;
}
- return hash;
}
public static String generateHash(int len) {