From e737214992da469ec667157737b6ccd918007776 Mon Sep 17 00:00:00 2001 From: Gregory Mitchell <54124162+gmitch215@users.noreply.github.com> Date: Wed, 31 Jul 2024 15:24:45 -0500 Subject: [PATCH] Add Password Generator --- src/main/kotlin/io/codemc/api/generator.kt | 9 +++++++++ .../kotlin/io/codemc/api/TestGenerator.kt | 20 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/main/kotlin/io/codemc/api/generator.kt create mode 100644 src/test/kotlin/io/codemc/api/TestGenerator.kt 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