Skip to content

Commit 3937308

Browse files
committed
big update
1 parent 7c4c456 commit 3937308

5 files changed

Lines changed: 211 additions & 50 deletions

File tree

build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
}
1212

1313
group = "net.Mirik9724"
14-
version = "0.1.5"
14+
version = "0.2.0"
1515

1616
repositories {
1717
mavenCentral()
@@ -29,6 +29,8 @@ dependencies {
2929
compileOnly("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
3030
kapt("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
3131

32+
implementation("com.nulab-inc:zxcvbn:1.9.0")
33+
3234
compileOnly("com.github.Mirik9724:MirikAPI:v0.1.5.10")
3335
compileOnly("net.elytrium.limboapi:api:1.1.26")
3436
}

src/main/kotlin/net/Mirik9724/MiLogin/MiCommands.kt

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,72 @@ package net.Mirik9724.MiLogin
22

33
import com.velocitypowered.api.command.SimpleCommand
44
import com.velocitypowered.api.proxy.Player
5+
import net.Mirik9724.MiLogin.MiLogin.Companion.authTimers
56
import net.Mirik9724.MiLogin.MiLogin.Companion.cache
67
import net.Mirik9724.MiLogin.MiLogin.Companion.data
78
import net.Mirik9724.MiLogin.MiLogin.Companion.isRegistered
8-
import net.Mirik9724.MiLogin.MiLogin.Companion.lFactory
99
import net.Mirik9724.MiLogin.MiLogin.Companion.notLoged
10+
import net.Mirik9724.MiLogin.PasswordGuard.isSimple
1011
import net.kyori.adventure.text.Component
1112
import net.kyori.adventure.text.format.NamedTextColor
1213
import java.time.LocalDateTime
1314

14-
class LogC {
15+
class LogC() {
1516
fun li(player: Player, args: Array<String>) {
17+
if (MiLogin.isOnCooldown(player.username.toString())) {
18+
player.sendMessage(Component.text(data["wait3Sec"]!!).color(NamedTextColor.RED))
19+
return
20+
}
21+
MiLogin.updateCooldown(player.username.toString())
22+
1623
if (args.size != 1) {
1724
return
1825
}
1926

20-
if(Hash(args[0]) != MiLogin.cache[player.username]?.pass){
27+
val attempts = MiLogin.loginAttempts.getOrDefault(player.username.toString(), 0)
28+
if (attempts >= MiLogin.maxAttempts) {
29+
MiLogin.loginAttempts.remove(player.username.toString())
30+
player.disconnect(Component.text(data["tooMoreTrys"]!!).color(NamedTextColor.RED))
31+
return
32+
}
33+
34+
if(Hash(args[0]) != cache[player.username.toString()]?.pass){
2135
player.sendMessage(Component.text(data["log.wrP"]!!).color(NamedTextColor.RED))
36+
37+
val newAttempts = attempts + 1
38+
MiLogin.loginAttempts[player.username.toString()] = newAttempts
39+
return
2240
}
2341

2442
player.sendMessage(Component.text(data["log.logged"]!!).color(NamedTextColor.GOLD))
2543
player.resetTitle()
2644

45+
MiLogin.loginAttempts.remove(player.username.toString())
46+
2747
cache[player.username.toString()] = MiData(
2848
time = LocalDateTime.now().toString()
2949
)
3050
MiLogin.saveData()
31-
32-
3351
notLoged.remove(player.username.toString())
34-
lFactory.respawnPlayer(player)
52+
authTimers[player.username.toString()]?.cancel()
53+
authTimers.remove(player.username.toString())
54+
MiLogin.bossBars[player.username.toString()]?.let {
55+
player.hideBossBar(it)
56+
MiLogin.bossBars.remove(player.username.toString())
57+
}
58+
59+
MiLogin.factory.passLoginLimbo(player);
3560
}
3661
}
3762

38-
class RegC {
63+
class RegC() {
3964
fun li(player: Player, args: Array<String>) {
4065
if(isRegistered(player.username.toString())){return}
66+
if (MiLogin.isOnCooldown(player.username.toString())) {
67+
player.sendMessage(Component.text(data["wait3Sec"]!!).color(NamedTextColor.RED))
68+
return
69+
}
70+
MiLogin.updateCooldown(player.username.toString())
4171

4272
if (args.size != 2) {
4373
return
@@ -48,7 +78,7 @@ class RegC {
4878
return
4979
}
5080

51-
if (isSimple(args[0])) {
81+
if (isSimple(args[0], player.username.toString())) {
5282
return
5383
}
5484

@@ -62,7 +92,14 @@ class RegC {
6292
MiLogin.saveData()
6393

6494
notLoged.remove(player.username.toString())
65-
lFactory.respawnPlayer(player)
95+
authTimers[player.username.toString()]?.cancel()
96+
authTimers.remove(player.username.toString())
97+
MiLogin.bossBars[player.username.toString()]?.let {
98+
player.hideBossBar(it)
99+
MiLogin.bossBars.remove(player.username.toString())
100+
}
101+
102+
MiLogin.factory.passLoginLimbo(player);
66103
}
67104
}
68105

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
package net.Mirik9724.MiLogin
22

3-
import java.security.MessageDigest
43
import java.security.SecureRandom
54
import net.Mirik9724.MiLogin.MiLogin.Companion.salt
5+
import javax.crypto.SecretKeyFactory
6+
import javax.crypto.spec.PBEKeySpec
7+
import com.nulabinc.zxcvbn.Strength
8+
import com.nulabinc.zxcvbn.Zxcvbn
69

710
fun Hash(password: String): String {
8-
val digest = MessageDigest.getInstance("SHA-256")
9-
digest.update(salt)
10-
val hashBytes = digest.digest(password.toByteArray(Charsets.UTF_8))
11+
val iterations = 10000
12+
val keyLength = 256
13+
14+
val spec = PBEKeySpec(
15+
password.toCharArray(),
16+
salt,
17+
iterations,
18+
keyLength
19+
)
20+
21+
val factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256")
22+
val hashBytes = factory.generateSecret(spec).encoded
23+
1124
return hashBytes.joinToString("") { "%02x".format(it) }
1225
}
1326

@@ -18,6 +31,14 @@ fun generateSalt(length: Int = 32): ByteArray {
1831
return salt
1932
}
2033

21-
fun isSimple(password: String) : Boolean {
22-
return false
23-
}
34+
object PasswordGuard {
35+
private val zxcvbn by lazy { Zxcvbn() }
36+
37+
fun isSimple(password: String, username: String): Boolean {
38+
if (password.length < 6) return true
39+
40+
val strength: Strength = zxcvbn.measure(password, listOf(username))
41+
42+
return strength.score < 2
43+
}
44+
}

0 commit comments

Comments
 (0)