codegen

128x128

Code Generator

Google Forms add-on that generates codes upon form submission. This add-on was borne of my need to establish a quiz as a pre-requisite to filling out a second form.

Now available through the GSuite Marketplace. Need to verify these codes? See the section #Verification below.

Form Code Generator was created for lightweight use cases only. It should not be used for complex or important workflows, as the security of these hash codes are not generated per state-of-the-art standards (e.g., does not support nonce values).

Disclaimer: I used plenty of code from Google Form Add-on’s original tutorial. In several cases, I even left Google’s original copyright notice.

screen shot 2017-06-16 at 4 59 00 am

screen shot 2017-06-22 at 2 59 10 pm

Verification

In effect, I use an MD5 hash combining the user’s email address, a salt the user sets, and a fixed random string to prevent rainbow tables.

If the Form Code Generator auth is not working, but you still want to generate codes, just skip step 1 below.

  1. Check the salt used in your form code generator. (Go to “Form Code Generator” > “Configurations”. In the side menu, the first form input is your salt.)
  2. In the relevant Google spread containing form responses, click on “Tools” > “Script Editor”, and paste the following code below. Save the script. (ctrl+s or cmd+s)
function MD5 (input) {
  var rawHash = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, input);
  var txtHash = '';
  for (i = 0; i < rawHash.length; i++) {
    var hashVal = rawHash[i];
    if (hashVal < 0) {
      hashVal += 256;
    }
    if (hashVal.toString(16).length == 1) {
      txtHash += '0';
    }
    txtHash += hashVal.toString(16);
  }
  return txtHash;
}
  1. In the relevant Google spread, identify which column contains the respondent’s email address. Say this is column C. Then, add the following code to any cell, to generate the code for the response in row 2:
=MD5(C2+YOUR_SALT + "dEstr0yR@1nB0wTAb1es”)

Make sure to replace YOUR_SALT. See the example spread for sample usage; the script for this spread, reproduced in the code block above, can be found here.

See the full Privacy Policy.