Simple way to licence cBot

Created at 20 Jan 2020, 14:29
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
PA

paralaxion

Joined 20.01.2020

Simple way to licence cBot
20 Jan 2020, 14:29


Hello All, 

Is there a simple way to licence a cBot, so i.e. the bot would run only on buyers account or buyers machine?

Thank you 

Patrick

 


@paralaxion
Replies

lisabeaney
24 Jan 2020, 13:24

RE:

paralaxion said:

Hello All, 

Is there a simple way to licence a cBot, so i.e. the bot would run only on buyers account or buyers machine?

Thank you 

Patrick

 

Yes, you can read the processor ID and then create a hash code from it. Write it to a text file and then check the contents of that file when your BOT runs...

The problem I've run in to licensing a single account is that people quite often have 2 or 3 demo accounts that they use for testing and then a different account for live trading... it can end up a bit messy !

I've ended up writing a licensing BOT that sends the request through to me and then I email the license code to the user, they copy & paste the code in to the License BOT and re-run it to generate the text file that contains the code. Any other BOTS you write can then check the contents of this file.


@lisabeaney

fxctrader
13 Dec 2020, 15:24

RE: RE:

lisabeaney said:

paralaxion said:

Hello All, 

Is there a simple way to licence a cBot, so i.e. the bot would run only on buyers account or buyers machine?

Thank you 

Patrick

 

Yes, you can read the processor ID and then create a hash code from it. Write it to a text file and then check the contents of that file when your BOT runs...

The problem I've run in to licensing a single account is that people quite often have 2 or 3 demo accounts that they use for testing and then a different account for live trading... it can end up a bit messy !

I've ended up writing a licensing BOT that sends the request through to me and then I email the license code to the user, they copy & paste the code in to the License BOT and re-run it to generate the text file that contains the code. Any other BOTS you write can then check the contents of this file.

Hi Lisa, do you mind to share the source code for your licensing bot? Just need some reference. Many thanks.

 


MadMike
13 Dec 2020, 18:50

This may help.

 

 


@MadMike

lisabeaney
14 Dec 2020, 19:57

RE: RE: RE:

fxctrader said:

lisabeaney said:

paralaxion said:

Hello All, 

Is there a simple way to licence a cBot, so i.e. the bot would run only on buyers account or buyers machine?

Thank you 

Patrick

 

Yes, you can read the processor ID and then create a hash code from it. Write it to a text file and then check the contents of that file when your BOT runs...

The problem I've run in to licensing a single account is that people quite often have 2 or 3 demo accounts that they use for testing and then a different account for live trading... it can end up a bit messy !

I've ended up writing a licensing BOT that sends the request through to me and then I email the license code to the user, they copy & paste the code in to the License BOT and re-run it to generate the text file that contains the code. Any other BOTS you write can then check the contents of this file.

Hi Lisa, do you mind to share the source code for your licensing bot? Just need some reference. Many thanks.

 

Hi,

This is the code I was working with :

// Description  : This BOT is used to generate and request License Codes
//              
// Author       : Lisa Beaney
// Date         : 7th January 2020
// 9th February 2020 - Changed to fix Telegram Security


using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using Telegram.Bot.Args;
using System.Text;
using System.Security.Cryptography;
using System.IO;
using System.Net;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.GMTStandardTime, AccessRights = AccessRights.FullAccess)]
    public class LondonBreakout : Robot
    {

        [Parameter("BOT Name")]
        public string BOTName { get; set; }

        [Parameter("Email Address")]
        public string EmailAddr { get; set; }
        [Parameter("License Key")]
        public string LicenseKey { get; set; }

        private string SendToHash;
        private string HashCode;
        //private readonly string BOTName = "CryptoBOT";
        private string RequestLicense;
        private const string GroupID = "Put your telegram Group ID here";

        protected override void OnStart()
        {
            // License key checks
            CheckLicenseKey();
        }


        private void CheckLicenseKey()
        {

            bool LicenseMatch;
            LicenseMatch = false;

            SendToHash = Account.Number + BOTName;
            // Generate the hash for the license code
            HashCode = MD5_hash(SendToHash);
            // Generate the text string to request the license code
            RequestLicense = "Email : " + EmailAddr + "\n Acct :" + Account.Number + "\n BOT : " + BOTName + " \n License Code : " + HashCode;

            // See if license key file exists
            // Read key
            String line;
            try
            {
                //Pass the file path and file name to the StreamReader constructor
                StreamReader sr = new StreamReader(Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents\\") + BOTName + "-BOT-license.txt");

                //Read the first line of text - this should be the license key
                line = sr.ReadLine();

                //Continue to read until you reach end of file
                while (line != null)
                {
                    // Check if this is the liceense code
                    if (line == HashCode)
                    {
                        LicenseMatch = true;
                        // If the license key is valid we don't need to go any further.
                        sr.Close();
                        Print("Valid license found");
                        Stop();
                    }
                    //Read the next line
                    line = sr.ReadLine();
                }

                //close the file
                sr.Close();

            } catch (Exception e)
            {
                Print("v2 Exception: " + e.Message);
            }

            // Check if the license key has matched. If it hasn't then send telegram.
            if (LicenseMatch == false)
            {
                Print("v2 License Key invalid - Requesting new license key");
                SendTelegramGroup(RequestLicense);
            }
            else
            {
                Print("v2 License valid - stopping");
                // If the license key matches then we don't need to do anything else
                Stop();
            }

            // Write license Key file
            // We will only want to do this if a license key has been entered.
            try
            {

                if (LicenseKey.Length > 0 && LicenseMatch == false)
                {

                    //Pass the filepath and filename to the StreamWriter Constructor
                    StreamWriter sw = new StreamWriter(Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents\\") + BOTName + "-BOT-license.txt");

                    //Write the license key
                    sw.WriteLine(LicenseKey);

                    //Close the file
                    sw.Close();
                    Print("v2 License file created");
                }
            } catch (Exception e)
            {
                Print("v2 Exception: " + e.Message);
            }
            Stop();
        }

        private void SendTelegramGroup(String TelegramText)
        {
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            // Print("Send Telegram called");
            var bot = new Telegram.Bot.TelegramBotClient("1022852061:AAEV0hzT-i8q_hTi1ZVNFUkc3psJk9WkwKQ");

            try
            {
                //Print("About to send");
                bot.SendTextMessageAsync(GroupID, TelegramText);

            } catch
            {
                //Print("Message Failed");
            }

        }
        public static String MD5_hash(string value)
        {
            StringBuilder Sb = new StringBuilder();

            using (var hash = MD5.Create())
            {
                Encoding enc = Encoding.UTF8;
                Byte[] result = hash.ComputeHash(enc.GetBytes(value));

                foreach (Byte b in result)
                    Sb.Append(b.ToString("x2"));
            }

            return Sb.ToString();
        }
    }
}

 


@lisabeaney

grandom
15 Sep 2022, 23:35

Check that License Generator

It binds the cBot to cTrader account using user ID number which is obtained by this indicator

 

 


@grandom

drkhashix
04 Aug 2023, 13:29

RE: RE: RE: RE:

lisabeaney said: 

fxctrader said:

lisabeaney said:

paralaxion said:

Hello All, 

Is there a simple way to licence a cBot, so i.e. the bot would run only on buyers account or buyers machine?

Thank you 

Patrick

 

Yes, you can read the processor ID and then create a hash code from it. Write it to a text file and then check the contents of that file when your BOT runs...

The problem I've run in to licensing a single account is that people quite often have 2 or 3 demo accounts that they use for testing and then a different account for live trading... it can end up a bit messy !

I've ended up writing a licensing BOT that sends the request through to me and then I email the license code to the user, they copy & paste the code in to the License BOT and re-run it to generate the text file that contains the code. Any other BOTS you write can then check the contents of this file.

Hi Lisa, do you mind to share the source code for your licensing bot? Just need some reference. Many thanks.

 

Hi,

This is the code I was working with :

// Description  : This BOT is used to generate and request License Codes//              // Author       : Lisa Beaney// Date         : 7th January 2020// 9th February 2020 - Changed to fix Telegram Securityusing System;using System.Linq;using cAlgo.API;using cAlgo.API.Indicators;using cAlgo.API.Internals;using cAlgo.Indicators;using Telegram.Bot.Args;using System.Text;using System.Security.Cryptography;using System.IO;using System.Net;namespace cAlgo.Robots{    [Robot(TimeZone = TimeZones.GMTStandardTime, AccessRights = AccessRights.FullAccess)]    public class LondonBreakout : Robot    {        [Parameter("BOT Name")]        public string BOTName { get; set; }        [Parameter("Email Address")]        public string EmailAddr { get; set; }        [Parameter("License Key")]        public string LicenseKey { get; set; }        private string SendToHash;        private string HashCode;        //private readonly string BOTName = "CryptoBOT";        private string RequestLicense;        private const string GroupID = "Put your telegram Group ID here";        protected override void OnStart()        {            // License key checks            CheckLicenseKey();        }        private void CheckLicenseKey()        {            bool LicenseMatch;            LicenseMatch = false;            SendToHash = Account.Number + BOTName;            // Generate the hash for the license code            HashCode = MD5_hash(SendToHash);            // Generate the text string to request the license code            RequestLicense = "Email : " + EmailAddr + "\n Acct :" + Account.Number + "\n BOT : " + BOTName + " \n License Code : " + HashCode;            // See if license key file exists            // Read key            String line;            try            {                //Pass the file path and file name to the StreamReader constructor                StreamReader sr = new StreamReader(Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents\\") + BOTName + "-BOT-license.txt");                //Read the first line of text - this should be the license key                line = sr.ReadLine();                //Continue to read until you reach end of file                while (line != null)                {                    // Check if this is the liceense code                    if (line == HashCode)                    {                        LicenseMatch = true;                        // If the license key is valid we don't need to go any further.                        sr.Close();                        Print("Valid license found");                        Stop();                    }                    //Read the next line                    line = sr.ReadLine();                }                //close the file                sr.Close();            } catch (Exception e)            {                Print("v2 Exception: " + e.Message);            }            // Check if the license key has matched. If it hasn't then send telegram.            if (LicenseMatch == false)            {                Print("v2 License Key invalid - Requesting new license key");                SendTelegramGroup(RequestLicense);            }            else            {                Print("v2 License valid - stopping");                // If the license key matches then we don't need to do anything else                Stop();            }            // Write license Key file            // We will only want to do this if a license key has been entered.            try            {                if (LicenseKey.Length > 0 && LicenseMatch == false)                {                    //Pass the filepath and filename to the StreamWriter Constructor                    StreamWriter sw = new StreamWriter(Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents\\") + BOTName + "-BOT-license.txt");                    //Write the license key                    sw.WriteLine(LicenseKey);                    //Close the file                    sw.Close();                    Print("v2 License file created");                }            } catch (Exception e)            {                Print("v2 Exception: " + e.Message);            }            Stop();        }        private void SendTelegramGroup(String TelegramText)        {            ServicePointManager.Expect100Continue = true;            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;            // Print("Send Telegram called");            var bot = new Telegram.Bot.TelegramBotClient("1022852061:AAEV0hzT-i8q_hTi1ZVNFUkc3psJk9WkwKQ");            try            {                //Print("About to send");                bot.SendTextMessageAsync(GroupID, TelegramText);            } catch            {                //Print("Message Failed");            }        }        public static String MD5_hash(string value)        {            StringBuilder Sb = new StringBuilder();            using (var hash = MD5.Create())            {                Encoding enc = Encoding.UTF8;                Byte[] result = hash.ComputeHash(enc.GetBytes(value));                foreach (Byte b in result)                    Sb.Append(b.ToString("x2"));            }            return Sb.ToString();        }    }}

The proposed method for licensing is to use a central and online licensing system known as the "License Server." In this approach, the process of generating, issuing, and managing licenses is done automatically and online, eliminating the need for accessing user information or interaction between the licensor and the user.

Here's how it works:

1. License Server: Set up a License Server that handles the generation, issuance, and management of licenses. The server utilizes a dedicated database to store and manage license information.

2. License Code Generation: Upon purchasing the robot, a unique license code is provided to the user by the License Server.

3. License Issuance: The user enters the license code into the robot after the purchase, and the robot sends this code to the License Server.

4. License Validation: The License Server checks and validates the license code. If it's valid, the server grants permission to the robot to continue functioning within the valid time frame.

5. Online Updates: Whenever there is a need for updates or license extensions, the user can interact with the License Server to perform the necessary actions.

Advantages of using the License Server approach:

- High Security: User information is protected, and only valid license codes are sent to the robots.
- Easy Management: Licenses are automatically managed, eliminating the need for manual interventions or contacting users.
- Flexibility: The central system allows for customized license types and durations based on specific user needs.
- Easy Updates: Updates can be performed online, providing users with a seamless process for continuous updates.

It's important to note that while the License Server approach enhances security, proper security measures need to be implemented on the License Server itself to prevent any unauthorized access and protect user data.

 


@drkhashix