-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
15 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,44 @@ | ||
package cc.baka9.catseedlogin.util; | ||
|
||
import java.security.SecureRandom; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.Properties; | ||
import java.util.Random; | ||
import java.util.regex.Pattern; | ||
|
||
public class Util { | ||
private static Pattern passwordDifficultyRegex = Pattern.compile("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$"); | ||
private static final Pattern passwordDifficultyRegex = Pattern.compile("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$"); | ||
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
private static final Random random = new SecureRandom(); | ||
|
||
public static boolean passwordIsDifficulty(String pwd){ | ||
public static boolean passwordIsDifficulty(String pwd) { | ||
return passwordDifficultyRegex.matcher(pwd).find(); | ||
} | ||
|
||
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
|
||
public static String time2Str(long time){ | ||
return sdf.format(new Date(time)); | ||
public static String time2Str(long time) { | ||
synchronized (sdf) { | ||
return sdf.format(new Date(time)); | ||
} | ||
} | ||
|
||
public static boolean checkMail(String e_mail){ | ||
public static boolean checkMail(String e_mail) { | ||
return e_mail.matches("[a-zA-Z0-9_]+@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)+"); | ||
} | ||
|
||
public static String randomStr(){ | ||
public static String randomStr() { | ||
int leftLimit = 97; // letter 'a' | ||
int rightLimit = 122; // letter 'z' | ||
int targetStringLength = 10; | ||
Random random = new Random(); | ||
StringBuilder buffer = new StringBuilder(targetStringLength); | ||
for (int i = 0; i < targetStringLength; i++) { | ||
int randomLimitedInt = leftLimit + (int) | ||
(random.nextFloat() * (rightLimit - leftLimit + 1)); | ||
int randomLimitedInt = leftLimit + random.nextInt(rightLimit - leftLimit + 1); | ||
buffer.append((char) randomLimitedInt); | ||
} | ||
|
||
return buffer.toString(); | ||
} | ||
|
||
public static boolean isOSLinux(){ | ||
Properties prop = System.getProperties(); | ||
String os = prop.getProperty("os.name"); | ||
public static boolean isOSLinux() { | ||
String os = System.getProperty("os.name"); | ||
return os != null && os.toLowerCase().contains("linux"); | ||
} | ||
|
||
|
||
} | ||
} |