Skip to content

Commit

Permalink
moved timestamps fix (#121)
Browse files Browse the repository at this point in the history
-moved the timestamps fix to EmailCodeUtils
  • Loading branch information
4reebah authored Aug 15, 2023
1 parent bacea60 commit 630c74d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion util/src/main/java/edu/sjsu/moth/util/EmailCodeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;

import java.text.SimpleDateFormat;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
Expand All @@ -12,6 +15,8 @@
public class EmailCodeUtils {

public static final SimpleDateFormat jsonDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
public static DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");

/* prepend 13 random bytes and append "frog" to the end. iterate 10,000 times (to make it slower) using SHA256*/
public final static Pbkdf2PasswordEncoder PASSWORD_ENCODER = new Pbkdf2PasswordEncoder("frog", 13, 10_000,
Pbkdf2PasswordEncoder.SecretKeyFactoryAlgorithm.PBKDF2WithHmacSHA256);
Expand All @@ -25,7 +30,10 @@ public class EmailCodeUtils {
PASSWORD_ENCODER.setEncodeHashAsBase64(true);
}

public static String now() {return jsonDateFormat.format(new Date());}
public static String now() {
ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
return now.format(dateFormatter);
}

/**
* return a salted and hashed password
Expand Down

0 comments on commit 630c74d

Please sign in to comment.