Unverified

Name

OTP or MFA using SSJS in SFMC

Language

Javascript

Rating

Voted: 0 by 0 user(s)

Codevault

ashu-OTP

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.4

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

07/06/2024

Important Note

This snippet has the following status:

Unverified

This snippet has not been verified, use with caution and at your own risk. See details provided by author in sidebar and click below to find out more.

OTP or MFA using SSJS in SFMC

 
                    
1<script runat="server">
2Platform.Load("Core", "1");
3var otp = Math.floor(100000 + Math.random() * 900000).toString();
4var customerEmail = "[email protected]";
5var otpDE = DataExtension.Init("OTP_Data_Extension");
6var inserted = otpDE.Rows.Add({ "Email": customerEmail, "OTP": otp });
7var emailDefinitionKey = "Your_Transactional_Email_Definition_Key";
8var sendStatus = TriggeredSend.Init(emailDefinitionKey).send({
9 "EmailAddress": customerEmail,
10 "SubscriberKey": customerEmail,
11 "Attributes": {
12 "OTP": otp
13 }
14});
15Write("<br>OTP: " + otp);
16Write("<br>Send Status: " + Stringify(sendStatus));
17</script>
18 
19%%[
20IF RequestParameter("submit") == "Submit" THEN
21 VAR @inputOTP, @email, @rows, @row, @storedOTP
22 SET @inputOTP = RequestParameter("otp")
23 SET @email = "[email protected]"
24 SET @rows = LookupRows("OTP_Data_Extension", "Email", @email)
25 IF RowCount(@rows) > 0 THEN
26 SET @row = Row(@rows, 1)
27 SET @storedOTP = Field(@row, "OTP")
28 IF @inputOTP == @storedOTP THEN
29 SET @accessGranted = "true"
30 DeleteDE("OTP_Data_Extension", "Email", @email)
31 ELSE
32 SET @accessGranted = "false"
33 ENDIF
34 ELSE
35 SET @accessGranted = "false"
36 ENDIF
37ENDIF
38]%%
39 
40<!DOCTYPE html>
41<html>
42<head>
43 <title>OTP Verification</title>
44</head>
45<body>
46 %%[ IF @accessGranted == "true" THEN ]%%
47 <p>OTP verified successfully! You now have access to the CloudPage.</p>
48 %%[ ELSE ]%%
49 <form method="post" action="">
50 <label for="otp">Enter OTP:</label>
51 <input type="text" id="otp" name="otp" required>
52 <input type="submit" name="submit" value="Submit">
53 </form>
54 %%[ IF RequestParameter("submit") == "Submit" AND @accessGranted == "false" THEN ]%%
55 <p style="color:red;">Invalid OTP. Please try again.</p>
56 %%[ ENDIF ]%%
57 %%[ ENDIF ]%%
58</body>
59</html>

0

Related Snippets

Please see some snippets below related to this snippet..

JavaScript

Public

1

Popup Keyboard Control

Added: 2 years ago

Last Updated: 2 years ago

Designed to allow visitor to navigate between popups (originally triggered by a button in a Unlimited Elements timeline widget).

JavaScript

Unverified

0

Divi Accordion Close by Defaulty

Added: 9 months ago

Last Updated: 9 months ago

Sets all tabs in the divi accordion to close by default

JavaScript

Unverified

0

Hide elements where link is empty

Added: 1 year ago

Last Updated: 1 year ago

I usually use this in a template where the theme doesn't support hiding fields for example a social media icon where the link is not set for one network e.g. Facbook but it is set for another e.g. Lin...

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

JavaScript

Unverified

0

OTP or MFA using SSJS in SFMC

Added: 3 months ago

Last Updated: 3 months ago