Skip to content

Commit

Permalink
Add Password Generator
Browse files Browse the repository at this point in the history
  • Loading branch information
gmitch215 committed Jul 31, 2024
1 parent 257f658 commit e737214
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/kotlin/io/codemc/api/generator.kt
Original file line number Diff line number Diff line change
@@ -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("")
20 changes: 20 additions & 0 deletions src/test/kotlin/io/codemc/api/TestGenerator.kt
Original file line number Diff line number Diff line change
@@ -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("/") }
}

}

0 comments on commit e737214

Please sign in to comment.