Registering respondents

We are managing the user through Cognito pool. But we will still keep track of the user token, which they get after successfully logging into AWS Cognito pool. We will map this token to one more ID, which is treated as an RID (Respondent ID). It's simple random characters prefixed by RID.

A simple top-level function is written to generate the random ID, which looks like the following code:

fun getRandomString(prefix: String): String {    val mixedBag = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"    val salt = StringBuilder()    val rnd = Random()    while (salt.length < 18) { // length of the random string.        val index = (rnd.nextFloat() * mixedBag.length).toInt()        salt.append(mixedBag[index])    }    val sb = StringBuilder().apply {        append(prefix) ...

Get Hands-On Serverless Applications with Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.