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:

    ![](upload://r62APRYu7VP7mJiUnOz3MDighx.png)

  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.

A)

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.

![](upload://8BgxXgZlTZwnEJhwUVVIXeCqT1F.png)

-----------------

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

![](upload://56cNPnkg88PTx4wsuMvIeD6IrFs.png)

 

---------------

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!

![](upload://xu1TQlTbzZ1TEDbb6S0S6mzfXle.png)

---------------

C) Then we create another number field

i. call it Verificaiton Input.

![](upload://cjW9sK4bRqMczw33bWhTDQcU34x.png)

---------------------

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!

![](upload://tSrPc0qjtziHS8cT32Cv6bj28nc.png)

 

Great! ...We're almost there!

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

![](upload://m7eEBSlwvx0gzONeCUanHtGkoVy.png)

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"

 

![](upload://zBjqCxiqEtI7zsOVGbkPTOL1txw.png)

---------------------

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

![](upload://zlEhl9rYayfx9Y3yQ5TdwofCznb.png)

-----------------------

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

![](upload://7EUkUMzE5vJIdbsc0KNAQxm8xVJ.png)

--------------------

iv.Then Click on the Registration area

![](upload://d7fBlegvpom7Db7kJCFWuDJ1z7i.png)

----------------

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.

![](upload://iMrDyItFGuvddyxHlblNIx8bE6z.png)

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

![](upload://iFgsmRG6UIk4U5Ay21sCCN29wVV.png)

 

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.

 

![](upload://qWdWa1Nf8gdwCw00avtWN5FN4TG.png)

Ok great, you made it!

Let me know how you get on?

Ramsey
Garmar | Product Development Consultant
ramsey@garmar.co.uk


What future can we create?

1 Like

@Ramseyfrom58202 this is awesome and I’ve used it in another app successfully. However, for some reason when I tried to implement this in my newest app the verification code changed from the code that was emailed, even though I have the rule to set the verification code to the random code when the verification code is blank, and the email field that is being sent is the “verification code“. Could this be an issue with the new environment? Have you heard of this happening at times?

Thank you so much!

I think I got it working. Had to delete and reenter the Validation code field and now it’s working. Odd. Thank you for posting this…so great!