mirror of
https://e.coding.net/circlecloud/AuthMe.git
synced 2024-12-22 06:48:55 +00:00
格式化加密部分...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
parent
ea4b75a212
commit
36b63958cc
@ -35,7 +35,7 @@ public class PasswordSecurity {
|
|||||||
method = event.getMethod();
|
method = event.getMethod();
|
||||||
|
|
||||||
if (method == null) {
|
if (method == null) {
|
||||||
throw new NoSuchAlgorithmException("Unknown hash algorithm");
|
throw new NoSuchAlgorithmException("未知的加密算法...");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method.comparePassword(hash, password, playerName)) {
|
if (method.comparePassword(hash, password, playerName)) {
|
||||||
@ -48,7 +48,7 @@ public class PasswordSecurity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (InstantiationException | IllegalAccessException e) {
|
} catch (InstantiationException | IllegalAccessException e) {
|
||||||
throw new NoSuchAlgorithmException("Problem with this hash algorithm");
|
throw new NoSuchAlgorithmException("加密算法" + algo.name() + "运行时出现问题...");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ public class PasswordSecurity {
|
|||||||
method = null;
|
method = null;
|
||||||
}
|
}
|
||||||
} catch (InstantiationException | IllegalAccessException e) {
|
} catch (InstantiationException | IllegalAccessException e) {
|
||||||
throw new NoSuchAlgorithmException("Problem with this hash algorithm");
|
throw new NoSuchAlgorithmException("加密算法" + alg.name() + "运行时出现问题...");
|
||||||
}
|
}
|
||||||
String salt = "";
|
String salt = "";
|
||||||
switch (alg) {
|
switch (alg) {
|
||||||
@ -150,13 +150,13 @@ public class PasswordSecurity {
|
|||||||
case CUSTOM:
|
case CUSTOM:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new NoSuchAlgorithmException("Unknown hash algorithm");
|
throw new NoSuchAlgorithmException("未知的加密算法...");
|
||||||
}
|
}
|
||||||
final PasswordEncryptionEvent event = new PasswordEncryptionEvent(method, playerName);
|
final PasswordEncryptionEvent event = new PasswordEncryptionEvent(method, playerName);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
method = event.getMethod();
|
method = event.getMethod();
|
||||||
if (method == null) {
|
if (method == null) {
|
||||||
throw new NoSuchAlgorithmException("Unknown hash algorithm");
|
throw new NoSuchAlgorithmException("未知的加密算法...");
|
||||||
}
|
}
|
||||||
return method.getHash(password, salt, playerName);
|
return method.getHash(password, salt, playerName);
|
||||||
}
|
}
|
||||||
|
@ -11,27 +11,31 @@ public class RandomString {
|
|||||||
|
|
||||||
private static final char[] chars = new char[36];
|
private static final char[] chars = new char[36];
|
||||||
|
|
||||||
|
static {
|
||||||
|
for (int idx = 0; idx < 10; ++idx) {
|
||||||
|
chars[idx] = (char) ('0' + idx);
|
||||||
|
}
|
||||||
|
for (int idx = 10; idx < 36; ++idx) {
|
||||||
|
chars[idx] = (char) ('a' + idx - 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final char[] buf;
|
private final char[] buf;
|
||||||
|
|
||||||
private final Random random = new Random();
|
private final Random random = new Random();
|
||||||
|
|
||||||
public RandomString(int length) {
|
public RandomString(final int length) {
|
||||||
if (length < 1)
|
if (length < 1) {
|
||||||
throw new IllegalArgumentException("length < 1: " + length);
|
throw new IllegalArgumentException("随机字符串长度小于1: " + length);
|
||||||
|
}
|
||||||
buf = new char[length];
|
buf = new char[length];
|
||||||
random.setSeed(Calendar.getInstance().getTimeInMillis());
|
random.setSeed(Calendar.getInstance().getTimeInMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
|
||||||
for (int idx = 0; idx < 10; ++idx)
|
|
||||||
chars[idx] = (char) ('0' + idx);
|
|
||||||
for (int idx = 10; idx < 36; ++idx)
|
|
||||||
chars[idx] = (char) ('a' + idx - 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String nextString() {
|
public String nextString() {
|
||||||
for (int idx = 0; idx < buf.length; ++idx)
|
for (int idx = 0; idx < buf.length; ++idx) {
|
||||||
buf[idx] = chars[random.nextInt(chars.length)];
|
buf[idx] = chars[random.nextInt(chars.length)];
|
||||||
|
}
|
||||||
return new String(buf);
|
return new String(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user