diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-02-12 14:32:37 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-02-12 14:32:37 +1300 |
commit | 596536b7a9efd22e8843f6cc5aeab91d39472441 (patch) | |
tree | 0c5af398f36a4d17655f136e57156bc8bab4ddf4 /src/org/traccar/database/DataManager.java | |
parent | d2c182e802504d94391fd932bbdae76dc33aaf49 (diff) | |
download | traccar-server-596536b7a9efd22e8843f6cc5aeab91d39472441.tar.gz traccar-server-596536b7a9efd22e8843f6cc5aeab91d39472441.tar.bz2 traccar-server-596536b7a9efd22e8843f6cc5aeab91d39472441.zip |
Add login back-end
Diffstat (limited to 'src/org/traccar/database/DataManager.java')
-rw-r--r-- | src/org/traccar/database/DataManager.java | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 602345df9..2c78a53c4 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -267,4 +267,25 @@ public class DataManager { } } + public long login(String name, String password) throws SQLException { + + Connection connection = dataSource.getConnection(); + try { + PreparedStatement statement = connection.prepareStatement( + "SELECT id FROM users WHERE name = ? AND password = ?;"); + try { + statement.setString(1, name); + statement.setString(2, password); + + ResultSet result = statement.executeQuery(); + result.next(); + return result.getLong("id"); + } finally { + statement.close(); + } + } finally { + connection.close(); + } + } + } |