PassGen is a Kotlin DSL-driven password generator that allows you to create secure and customizable passwords with ease.
You can include PassGen in your Kotlin project via JitPack.
For Gradle Kotlin DSL (build.gradle.kts
), add the JitPack repository and dependency as follows:
repositories {
maven(url = "https://jitpack.io")
}
dependencies {
implementation("com.github.offrange:passgen:v0.0.3-beta")
}
For Maven, add the JitPack repository and dependency to your pom.xml
file:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Then, include the PassGen dependency:
<dependency>
<groupId>com.github.offrange</groupId>
<artifactId>passgen</artifactId>
<version>v0.0.3-beta</version>
</dependency>
Generate a password using lowercase letters, uppercase letters, digits, and punctuations that is 12 characters long:
fun main() {
val password = generate(Password) {
lowercase()
uppercase()
digits()
punctuations()
length(12)
}
println("Generated Password: $password")
}
Generate an alphanumeric password (including lowercase letters, uppercase letters, digits, and punctuations)
using alphanumeric()
. This function internally utilizes the functions defined in the example above to
include the necessary generation pools:
fun main() {
val password = generate(Password) {
alphanumeric()
length(12)
}
println("Generated Alphanumeric Password: $password")
}
Create a password using a custom generation pool:
fun main() {
val customPool = "ABC123".toCharPool() // Same as GenerationPool.fromString("ABC1234")
val password = generate(Password) {
custom(customPool)
length(8)
}
println("Generated Password with Custom Generation Pool: $password")
}
Combine multiple custom generation pools to generate a password:
fun main() {
val customPool1 = "ABC".toCharPool()
val customPool2 = "123".toCharPool()
val password = generate(Password) {
+customPool1 // Same as custom(customPool1)
+customPool2 // Same as custom(customPool2)
length(10)
}
println("Generated Password with Multiple Custom Generation Pools: $password")
}
In addition to generating passwords, you can use the library to generate passphrases.
fun main() {
val passphrase = generate(Passphrase) {
separator = '-' // Default separator between words
custom(GenerationPool.fromStrings("word1", "word2", "word3")) // Add custom words to the passphrase pool
loadFile(File("path/to/wordlist")) // Load words from a file as entries in the passphrase pool
}
println("Generated Passphrase: $passphrase")
}
Contributions to PassGen are welcome! Feel free to open issues and pull requests on the GitHub repository.
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.