aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/UserQueries.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/server/UserQueries.java')
-rw-r--r--src/main/java/com/juick/server/UserQueries.java26
1 files changed, 6 insertions, 20 deletions
diff --git a/src/main/java/com/juick/server/UserQueries.java b/src/main/java/com/juick/server/UserQueries.java
index 2cd557c6..5588d8e4 100644
--- a/src/main/java/com/juick/server/UserQueries.java
+++ b/src/main/java/com/juick/server/UserQueries.java
@@ -199,27 +199,13 @@ public class UserQueries {
return uname != null && uname.length() >= 2 && uname.length() <= 16 && uname.matches("[a-zA-Z0-9\\-]+");
}
- public static int checkPassword(Connection sql, String username, String password) {
- int uid = 0;
- PreparedStatement stmt = null;
- ResultSet rs = null;
- try {
- stmt = sql.prepareStatement("SELECT id,passw FROM users WHERE nick=?");
- stmt.setString(1, username);
- rs = stmt.executeQuery();
- if (rs.first()) {
- if (password.equals(rs.getString(2))) {
- uid = rs.getInt(1);
- } else {
- uid = -1;
- }
- }
- } catch (SQLException e) {
- LOGGER.log(Level.SEVERE, "sql exception", e);
- } finally {
- Utils.finishSQL(rs, stmt);
+ public static int checkPassword(JdbcTemplate sql, String username, String password) {
+ String realPassword = sql.queryForObject("SELECT passw FROM users WHERE nick=?", String.class, username);
+ if (realPassword.equals(password)) {
+ return UserQueries.getUserByName(sql, username).getUID();
+ } else {
+ return -1;
}
- return uid;
}
public static int getUserOptionInt(Connection sql, int uid, String option, int defaultValue) {