aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/database/DataManager.java3
-rw-r--r--src/org/traccar/helper/Hashing.java20
-rw-r--r--src/org/traccar/model/User.java21
3 files changed, 24 insertions, 20 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index fdab359f4..9633ada58 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -38,6 +38,7 @@ import javax.sql.DataSource;
import org.traccar.Context;
import org.traccar.helper.DriverDelegate;
+import org.traccar.helper.Hashing;
import org.traccar.helper.Log;
import org.traccar.http.JsonConverter;
import org.traccar.model.Device;
@@ -219,7 +220,7 @@ public class DataManager {
public User login(String email, String password) throws SQLException {
return QueryBuilder.create(dataSource, properties.getProperty("database.loginUser"))
.setString("email", email)
- .setBytes("password", User.sha256(password))
+ .setBytes("password", Hashing.sha256(password))
.executeQuerySingle(new User());
}
diff --git a/src/org/traccar/helper/Hashing.java b/src/org/traccar/helper/Hashing.java
new file mode 100644
index 000000000..7e7579ede
--- /dev/null
+++ b/src/org/traccar/helper/Hashing.java
@@ -0,0 +1,20 @@
+package org.traccar.helper;
+
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+public class Hashing {
+
+ public static byte[] sha256(String text) {
+ try {
+ MessageDigest md = MessageDigest.getInstance("SHA-256");
+ md.update(text.getBytes(StandardCharsets.UTF_8));
+
+ return md.digest();
+ } catch (NoSuchAlgorithmException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
diff --git a/src/org/traccar/model/User.java b/src/org/traccar/model/User.java
index 9186e66c5..410bc4d74 100644
--- a/src/org/traccar/model/User.java
+++ b/src/org/traccar/model/User.java
@@ -15,9 +15,7 @@
*/
package org.traccar.model;
-import java.io.UnsupportedEncodingException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
+import org.traccar.helper.Hashing;
public class User implements Factory {
@@ -40,7 +38,7 @@ public class User implements Factory {
private byte[] password;
public byte[] getPassword() { return password; }
- public void setPassword(String password) { this.password = sha256(password); }
+ public void setPassword(String password) { this.password = Hashing.sha256(password); }
private boolean readonly;
@@ -61,19 +59,4 @@ public class User implements Factory {
private double longitude;
private int zoom;
-
-
- public static byte[] sha256(String text) {
- try {
- MessageDigest md = MessageDigest.getInstance("SHA-256");
-
- md.update(text.getBytes("UTF-8"));
- byte[] digest = md.digest();
- return digest;
- } catch (NoSuchAlgorithmException e) {
- throw new RuntimeException(e);
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
- }
}