Posts

How to create License Key for Blogger template using JavaScript


In this article, I will share with you the JavaScript code to activate the license key for Blogger template and how to store the license key.

Recently you may have seen on my Blog that I shared some templates that they used license keys to activate, right? For example, Plus UI v2.6.1 or Apmody v1.4, although the 2 templates have JavaScript encryption, I still don't know how to solve it, but I know where the JavaScript code to activate the license key is, so I replaced it with another similar code.

And in this article I will share with you the JavaScript code to activate the license key for Blogger template and how to store the license key.

How License Key works

The way it works is very simple that you will save the information to create a License Key on Google Script to increase security and from that information I will convert it to Base64 encoding like this dFu5d8WerUWerZN3OHf=. It can also be used similarly to writing Github but it will be very easy for others to know and change. The License Key will be managed by you and each License Key can only be used on 1 fixed Blog.

How to create a Google Script containing License Key information

There are 2 ways to create Google Script containing License Key information but I will guide you through the fastest way that I have used.

Step 1: Go to https://script.google.com/home and select New project .

How to create License Key for Blogger template using simple JavaScript

Step 2: Name your project and replace all the existing code with the following code:

function doGet() {
  var nldblog = ContentService.createTextOutput();
  nldblog.append('{"user":[{"no":0,"name":"","url":"","id":"","code":""},{"no ":1,"name":"","url":"","id":"","code":""},{"no":2,"name":"","url" :"","id":"","code":""},{"no":3,"name":"","url":"","id":"","code" :""},{"no":4,"name":"","url":"","id":"","code":""},{"no":5,"name ":"","url":"","id":"","code":""},{"no":6,"name":"","url":"","id ":"","code":""},{"no":7,"name":"","url":"","id":"","code":""},{ "no":8,"name":"","url":"","id":"","code":""},{"no":9,"name":""," url":"","id":"","code":""},{"no":10,"name":"","url":"","id":""," code":""}]}');
  return nldblog;
}

How to create License Key for Blogger template using simple JavaScript

Each License Key will be an object including the following:

{"no":0,"name":"","url":"","id":"","code":""}

In which nois the serial number, urlis the url of the blog that activates the key, idis the id of the blog that activates the key, codethis will be the information to create the license key. For example, an object is as follows:

{"no":0,"name":"NLD Blog","url":"www.nldblog.com","id":"6311614170532925167","code":"nldblogcode"}

Step 3: Then you select Deploy and then select New deployment. A popup will appear and in the Select type column you select the gear icon and select Web app . In the Configuration column you set it as follows:

How to create License Key for Blogger template using simple JavaScript

Then select Deloy . Next, the URL of the Web app will appear. Please save it in notepad or somewhere.

How to create License Key for Blogger template using simple JavaScript

To add a new license key information object, you add or edit an object similar to the above and in step 3, you select Deply and then select Manage deployments . Next, a popup appears in the Configuration column , you select the pen icon (Edit), then in the Version section, you select New version and click Deploy .

That's it for the Google Script part.

Add license checking JavaScript code to template

Step 1: Add the code below after the tag <body>.

<script><b:eval expr='"const blogID='" + data:blog.blogId + "';"'/></script>

Step 2: Continue adding the code below before the tag </body>.

< script > //<![CDATA[
    var licensekey = "license key";
//]]> </ script >

This code will be public to receive license key and licensekey here will be replaced with License Key you created.

Step 3: Add the following code below the code just added in step 2.

<script>//<![CDATA[
    var e, s = "https://www.nldblog.com";
    function o() {
        window.alert("Invalid License Key"), document.body.innerHTML = "", window.location.href = s
    }
    try {
        e = atob(licensekey)
    } catch (e) {
        try {
            o()
        } catch (e) {
            window.location.href = s
        }
    }
    var n = e.split("-"),
        l = n[0];
    if (void 0 === (n = n[1])) try {
        o()
    } catch (e) {
        window.location.href = s
    }
    str = [n], getAJ({
        url: "Web app URL",
        async: !0,
        success: function (e) {
            var n = JSON.parse(e).user[str];
            if (void 0 === n) try {
                o()
            } catch (e) {
                window.location.href = s
            }
            var u = n.id,
                d = n.code,
                a = n.url;
            try {
                if (blogID + l === u + d && 0 != function (e) {
                        if (-1 == window.location.pathname.indexOf("/b/preview") && -1 == window.location.pathname.indexOf("/b/blog-preview")) return e == window. location.hostname
                    }(a)) return void console.log('Licensed to: ' + n.name + ', Licensed for: ' + n.url);
                try {
                    o()
                } catch (e) {
                    window.location.href = s
                }
            } catch (e) {
                try {
                    o()
                } catch (e) {
                    window.location.href = s
                }
            }
        }
    })
    function getAJ(e) {
        var r = new XMLHttpRequest;
        try {
            r = new XMLHttpRequest
        } catch (t) {
            try {
                r = new ActiveXObject("Msxml2.XMLHTTP")
            } catch (t) {
                try {
                    r = new ActiveXObject("Microsoft.XMLHTTP")
                } catch (t) {
                    return console.warn("Something went wrong!"), !1
                }
            }
        }
        r.onreadystatechange = function () {
            var n;
            4 == r.readyState && (200 == r.status ? (n = r.responseText, e.success(n)) : "function" == typeof e.error && e.error(r))
        }, r.open("GET", e.url, e.async), r.send()
    }
//]]></script>

Replace https://www.nldblog.comwith the URL that will redirect when the License Key is incorrect and Web app URLwith the Web app URL that I told you to save in notepad in the previous section.

And to increase security, you should encrypt the JavaScript inside the tag <script>//<![CDATA[ ... //]]></script>using some of the following tools or your own encryption method.

https://www.cleancss.com/javascript-obfuscate or https://javascriptobfuscator.com/Javascript-Obfuscator.aspx you can encrypt multiple times for higher security.

That's it, next is how you get the License Key in base64 code format.

How to create License Key

In the section How to create a Google Script containing License Key information , I mentioned an object containing the following information:

{"no":0,"name":"NLD Blog","url":"www.nldblog.com","id":"6311614170532925167","code":"nldblogcode"}

Here the License Key will have a structure including code-no for example the object above my License Key will be nldblogcode-0 converted to base64 it will become bmxkYmxvZ2NvZGUtMA== .

To convert the License Key to base64 format, use the following tool Base64 Converter, paste the License Key in code-no format and click Encode . At this point, you will receive a base64 code. To reverse the translation, do the same and then click Decode .

Conclude

That's it, I just guided you on how to create a License Key for a Blogger template using simple JavaScript to help protect your template when it is ripped or sold by others to avoid sharing the template. If you have any problems or questions, please comment below and I will answer if possible.

About the author

Plus UI Blogger Templates
Plus UI V3.0.0 Blogger Template with Additional Codes | No Licence. Plus UI is a premium Blogger template that comes with a sleek and modern design along with a range of customization options to make your brand unique. This template is perfect for b…

Post a Comment