Custom Software Services for Forward-Thinking Organizations

View Original

A Simple Guide to Implement Hashing into your Knack APPs

Skills: JavaScript, JQuery, AJAX, HTMLLevel: Medium

Hello Folks!

If you ever need to store sensitive information in the database, we advise you to try the solution based on data encryption or hashing, which in summary converts a value into an encrypted string of numbers and characters.

Let's suppose we want to store people's IDs in our database, but we don't want to save the ID in the database in plain text for the world to see. Yet, we want the ID to be searchable from a Knack.

Today we’ll show you the exact steps you’ll need to know to incorporate the Hashing technique into your Knack applications.

To see a working example, follow these link

Remember to always follow this guide:

1. Set up the Object and Field in Knack.

To start, let’s set up an object in Knack with two fields, the field where the hash code will be saved, in our example the ID of the person, and the field with the name of the person that will be retrieved.

Make sure to mark the “Identification number” field as mandatory (*); this will let the user know they must enter the information before saving it. 

 
2. Add the Search and Insert forms to your page.

3. Add the JavaScript code 

Invoke the MD5 Library

You’ll need to invoke a hashing library using JavaScript. The library used in this example is found here https://cdnjs.cloudflare.com/ajax/libs/blueimp-md5/2.13.0/js/md5.min.js

See this content in the original post

Insert:

Once you have the hashing library ready, you need to capture the knack-form-submit event of the form so the person ID is converted to an encrypted hashed value before it’s saved in the database.

See this content in the original post

Search:

Likewise, you’ll need to capture the ‘click’ event in the Search button so that value to search is hashed before the code looks for the match in the database.

See this content in the original post

Did you find this insightful?

Please leave a comment below and let us know!

Make IT Happen!