implemented resetting passwords
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -4,12 +4,9 @@ import de.srsoftware.tools.translations.Translation;
|
||||
import de.srsoftware.widerhall.data.MailingList;
|
||||
import de.srsoftware.widerhall.data.User;
|
||||
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Multipart;
|
||||
import javax.mail.Part;
|
||||
import javax.mail.internet.AddressException;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
@@ -19,6 +16,7 @@ import java.security.NoSuchAlgorithmException;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static de.srsoftware.widerhall.Constants.*;
|
||||
@@ -28,6 +26,14 @@ public class Util {
|
||||
private static final MessageDigest SHA256 = getSha256();
|
||||
private static final String EMAIL_PATTERN = "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^-]+(?:\\.[a-zA-Z0-9_!#$%&'*+/=?`{|}~^-]+)*@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$";
|
||||
|
||||
public static char boundedChar(int i) {
|
||||
i = (i<0 ? -i : i) % 62;
|
||||
i += '0';
|
||||
if (i>57) i+=7;
|
||||
if (i>90) i+=6;
|
||||
return (char) i;
|
||||
}
|
||||
|
||||
public static String dropEmail(String tx) {
|
||||
return tx.replaceAll( "[.\\-\\w]+@[.\\-\\w]+", "[email_removed]");
|
||||
}
|
||||
@@ -119,6 +125,18 @@ public class Util {
|
||||
return email.matches(EMAIL_PATTERN);
|
||||
}
|
||||
|
||||
public static String randomString(int length) {
|
||||
Random rand = new Random();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i=0; i<length; i++) {
|
||||
int k = rand.nextInt();
|
||||
char c = boundedChar(k);
|
||||
System.out.println("adding '"+c+"'…");
|
||||
sb.append(c);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String sha256(String s) {
|
||||
byte[] bytes = SHA256.digest(s.getBytes(StandardCharsets.UTF_8));
|
||||
return hex(bytes);
|
||||
|
||||
Reference in New Issue
Block a user