- if (rs.next()) {
- String dbHash = rs.getString(1);
- String hash = PasswordHash.verifyHash(pw, dbHash);
- if (hash != null) {
- if ( !hash.equals(dbHash)) {
- try (GigiPreparedStatement gps = new GigiPreparedStatement("UPDATE `users` SET `password`=? WHERE `email`=?")) {
- gps.setString(1, hash);
- gps.setString(2, un);
- gps.executeUpdate();
- }
+ if ( !rs.next()) {
+ throw new GigiApiException("Username and password didn't match.");
+ }
+
+ User user = User.getById(rs.getInt(2));
+ if (user == null) {
+ throw new GigiApiException("Username and password didn't match.");
+ }
+
+ String dbHash = rs.getString(1);
+ String hash = PasswordHash.verifyHash(pw, dbHash);
+ if (hash != null) {
+ if ( !hash.equals(dbHash)) {
+ try (GigiPreparedStatement gps = new GigiPreparedStatement("UPDATE `users` SET `password`=? WHERE `email`=?")) {
+ gps.setString(1, hash);
+ gps.setString(2, un);
+ gps.executeUpdate();