diff --git a/src/main/kotlin/io/codemc/api/generator.kt b/src/main/kotlin/io/codemc/api/generator.kt new file mode 100644 index 0000000..d918655 --- /dev/null +++ b/src/main/kotlin/io/codemc/api/generator.kt @@ -0,0 +1,9 @@ +@file:JvmName("Generator") + +package io.codemc.api + +private val pwdChars = ('a'..'z') + ('A'..'Z') + ('0'..'9') + "!@#-_^*".toList() + +fun createPassword(size: Int): String = (1..size) + .map { pwdChars.random() } + .joinToString("") \ No newline at end of file diff --git a/src/test/kotlin/io/codemc/api/TestGenerator.kt b/src/test/kotlin/io/codemc/api/TestGenerator.kt new file mode 100644 index 0000000..bd12c07 --- /dev/null +++ b/src/test/kotlin/io/codemc/api/TestGenerator.kt @@ -0,0 +1,20 @@ +package io.codemc.api + +import org.junit.jupiter.api.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +object TestGenerator { + + @Test + fun testCreatePassword() { + val p1 = createPassword(16) + assertEquals(p1.length, 16) + assertTrue { !p1.contains("=") } + + val p2 = createPassword(32) + assertEquals(p2.length, 32) + assertTrue { !p2.contains("/") } + } + +} \ No newline at end of file