Password Generator Library for Android

Abhinav Singh
The Startup
Published in
2 min readAug 2, 2020
Image source: https://www.noip.com/blog/2013/12/04/9-easy-ways-choose-safe-secure-password/

Ever faced a situation when you want to add a password generating functionality in your app but don’t want to code it. Don’t worry PasswordGeneratorLibrary has come to your rescue.

PasswordGeneratorLibrary is an android open-source library compatible with both Java and Kotlin. It’s very easy to set up and use and provides you all the functionalities you need for generating passwords in your app.

To integrate the password generator library in your app do the following steps:

Step 1: Add the JitPack repository to your build file. Add it to your root build.gradle at the end of repositories:

allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}

Step 2: Add the dependency

dependencies {
implementation 'com.github.abhinav0612:PasswordGeneratorLibrary:Tag'
}

Now just add the following lines wherever you need to generate a password.

var passwordGenerator = PasswordGenerator(12,                           
includeUpperCaseLetters = true,
includeLowerCaseLetters = true,
includeSymbols = true,
includeNumbers = true)

var generatedPassword = passwordGenerator.generatePassword()

The library also has an in-built PasswrodGeneratorActivity which you can add in your app to make your task easier.

Password Generating Activity

You can start the PasswordGeneratorActivity normally or for a result.

val intent = Intent(this,PasswordGeneratorActivity::class.java)
startActivity(intent)

OR

val intent = Intent(this,PasswordGeneratorActivity::class.java)
startActivityForResult(intent,PasswordGeneratorActivity.REQUEST_CODE)
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if(requestCode == PasswordGeneratorActivity.REQUEST_CODE){
if(resultCode == Activity.RESULT_OK){
var password = data?.getStringExtra(PasswordGeneratorActivity.PASSWORD_GENERATED)
}
}
}

From the onActivityResult method, you can get the generated password with the following line.

data?.getStringExtra(PasswordGeneratorActivity.PASSWORD_GENERATED)

Hurray! Now you have successfully integrated the library in your app and have an awesome UI for users to create a password.

Share with your friends and colleagues if you find this helpful.

Let’s connect on LinkedIn, Github, Twitter.

--

--

Abhinav Singh
The Startup

Software Engineer | Linkedin @cachedengineer | Twitter @cached_engineer