How do I verify a user's email? The simplest solution

If you're building an app that public users can sign up to, then the “best-practice” thing to do is make sure they verify their email before they can enter your platform.

By the end of this post you will know how to set up your app so that the user is not verified (the User Status is not Active) until the user enter's a 4 digit passcode that they recevied from their email!

This for anyone even with no coding ability, in the true Knack spirit, we're going to do this in the simplest way possible.

  1.  First we need to create a few fields and add a few rules in your User Role record that will:
    A) Create the 4 digit passcode generator (it's easier than it sounds)called "Code Generator"
    B) Store the 4 digit code so it doesnt keep changing. "Verification Code"
    C) A field called "Verification Input" where the code that the user inputs is stored.
    D) A Yes/No field called "Email Verified" that changes to Yes when the passcode is entered correctly.

    This is how it looks in the record:


  2. The next step is sending an email to the user's email containing the 4 digit passcode.

  3. Then we're going to create a form in your ome page where the user inputs the 4 digit code. We're also going to add some page rules that hides everything except for the input form until the passcode is entered.


Let's begin...

1. Create the fields in User Roles.


i. Go to your User Role record and create a new field called "Code Generator".

ii. In the equation field create a random number generator that creates a 4 digit code between 1000 and 9999. copy and insert this: randomInt(1000,9999).

iii. Make sure the equation type is numeric and all other fields are the same as that showing in the picture below.



B) Then we will create a new Number field and we're going to name it Verification Code.




ii. Then click Conditional Rules. When Verication Code is Blank, we set the record value of this field to Code Generator. This gives our passcode fixed in place!



C) Then we create another number field

i. call it Verificaiton Input.



D) Now create a Yes/No field called Email Verified![](upload://qanAzrusM6dZfssG8hPFJ7O5tLU.png)


ii. Then we are going to add a Condition Rule, where if the Verication code is identical to the Verification Input then Email Verified will be set to Yes!



Great! ...We're almost there!

You should have fields in your User Role object that look like this:


Next on the list, sending an email when a user signs up.


2. If you already have a sign up area for your user then you can skip this part. Otherwise, go to the Pages area. Click +Add and create a page where a user must login to access it. Limit the permissions to the specific user roles and click the name of the user role object where you added the fields, mine happens to be called Standard User. Select an object that you want to add in this page and then click Add New Page. BTW i called my area "Demo Data"




ii. Click on the log in part of the page you just created



iii. Make sure user registration is set to Open, (not Approved).



iv.Then Click on the Registration area



v. Then go to Emails and then click on Send a Custom Email, ![](upload://52Nkelkicgx7WFZeMUbDBMd6Uww.png)

Great now we're very close to getting there, I promise!


3. Now it's time to add the form in your home page.

i. Go to the views part of your home page, and add Form. Make sure you click "update the logged-in Standard User" or the name of the User Role tht contains the fields we added.


ii. Then clear all other fields except for Verification Input and click Save.



iii. Then we go back to the home page Views and click Rules. We're going to add a new rule that hides the Verification Input form when Email Verified is set to Yes.

As shown in the picture we need two rules, one where Email Verified field is Yes, and the other where Email Verified is not Yes.

My Demo Data is called Invoice Entries, in your case it will be something different,

Make sure the form is hidden when Email Verified is Yes

And inversely, make sure the opposite is the case when Email Verified is Not Yes.



Ok great, you made it!

Let me know how you get on?

Garmar | Product Development Consultant

What future can we create?