Get user's username

 
Hi everyone, is that possible to get user's username from metaeditor (or something like this, auth key etc.)?

I develop a advisor and i want to verify users authentication in somewhere of my advisor from remote access.
 
Rabia Yoruk: Hi everyone, is that possible to get user's username from metaeditor (or something like this, auth key etc.)? I develop a advisor and i want to verify users authentication in somewhere of my advisor from remote access.
Only the Account's Client Name via "AccountInfoString( ACCOUNT_NAME )", not the MQL5 Username!
 
Rabia Yoruk is that possible to get user's username from metaeditor (or something like this, auth key etc.)?

Your code is running on a broker's account. There is no username with brokers.

If you could get the user's name, he could run your code on 32 separate terminals with 32 separate accounts. That's not what you want, is it?
          PAIRS/SYMBOLS ON A CHART - General - MQL5 programming forum #1 2020.12.14

 
Fernando Carreiro:
Only the Account's Client Name via "AccountInfoString( ACCOUNT_NAME )", not the MQL5 Username!

First of all thank you for your attention, so is this specific for every user? and users can access it through the metatrader interface?

 
William Roeder:

Your code is running on a broker's account. There is no username with brokers.

If you could get the user's name, he could run your code on 32 separate terminals with 32 separate accounts. That's not what you want, is it?
          PAIRS/SYMBOLS ON A CHART - General - MQL5 programming forum #1 2020.12.14

I mean actually login information or any information specific to the user. Username is not a particularly necessary. However for verification, the user must also have access to this information.

 
Rabia Yoruk: First of all thank you for your attention, so is this specific for every user? and users can access it through the metatrader interface?

No it is not specific enough to every user, because there are people with the same name all over the world! So use the other account information to make it more specific (see code below).

You said you wanted to extract the information via your EA running on a customer's machine. That is what I gave you! The customer already knows his own name and the name on his trading account! He does not need to extract it, but yes he can see it right under the Account names in MetaTrader's Navigator window.

Forum on trading, automated trading systems and testing trading strategies

EA limit code

Fernando Carreiro, 2017.09.10 22:17

Here is a sample of my own code that I use, but it is up to you to implement properly. I'm not offering any support on it. It is up to you to do the necessary research and learning.

//+------------------------------------------------------------------------------------+
// Initialisation Event Function
//+------------------------------------------------------------------------------------+
int OnInit()
{
   // Check Licensing Restrictions
   if( boolRestrictOnInit() ) return( INIT_FAILED );

   // ...

   return( INIT_SUCCEEDED );  // Initialisation complete
}
//+------------------------------------------------------------------------------------+
// Tick Event Function
//+------------------------------------------------------------------------------------+
void OnTick()
{
   // Check Licensing Restrictions
   if( boolRestrictOnTick() ) return;
   
   /// ...
}
//+------------------------------------------------------------------------------------+
// Function to Test Restrictions during Initialisation
//+------------------------------------------------------------------------------------+
bool boolRestrictOnInit()
{
   boolRestrictions =
      boolRestrictExpiration     ||
      boolRestrictAccountNumber  ||
      boolRestrictAccountName    ||
      boolRestrictAccountServer  ||
      boolRestrictAccountCompany ||
      boolRestrictDemoAccount    ||
      boolRestrictSymbols;

   if( boolRestrictions )
   {
      boolRestrictionsUnverified = true;

      if( (bool) TerminalInfoInteger( TERMINAL_CONNECTED ) )
      {
         long longAccountNumber = AccountInfoInteger( ACCOUNT_LOGIN );
         if( longAccountNumber > 0 )
         {
            if( boolRestrictAccountNumber )
               { if( longAccountNumber                        != longRestrictAccountNumber )
                  { return( boolRestrictAlert() ); } }
            if( boolRestrictAccountName )
               { if( AccountInfoString( ACCOUNT_NAME )        != strRestrictAccountName    )
                  { return( boolRestrictAlert() ); } }
            if( boolRestrictAccountServer )
               { if( AccountInfoString( ACCOUNT_SERVER )      != strRestrictAccountServer  )
                  { return( boolRestrictAlert() ); } }
            if( boolRestrictAccountCompany )
               { if( AccountInfoString( ACCOUNT_COMPANY )     != strRestrictAccountCompany )
                  { return( boolRestrictAlert() ); } }
            if( boolRestrictDemoAccount )
               { if( AccountInfoInteger( ACCOUNT_TRADE_MODE ) != ACCOUNT_TRADE_MODE_DEMO   )
                  { return( boolRestrictAlert() ); } }
            if( boolRestrictSymbols() )
               { return( boolRestrictAlert() ); }

            boolRestrictionsUnverified = false;
         }
      }
   }
   return( false );
}
//+------------------------------------------------------------------------------------+
// Function to Test Variations of Restricted Symbols
//+------------------------------------------------------------------------------------+
bool boolRestrictSymbols()
{
   if( boolRestrictSymbols )
   {
      int intSymbolCount = ArraySize( strRestrictSymbols );
      if( intSymbolCount == 0 ) return( false );
      for( int i = 0; i < intSymbolCount; i++ )
      {
         if( StringFind( _Symbol, strRestrictSymbols[i] ) != WRONG_VALUE ) return( false );
         int
            intLen  = StringLen( strRestrictSymbols[i] ),
            intHalf = intLen / 2;
         string
            strLeft  = StringSubstr( strRestrictSymbols[i], 0, intHalf ),
            strRight = StringSubstr( strRestrictSymbols[i], intHalf, intLen - intHalf );
         if( ( StringFind( _Symbol, strLeft  ) != WRONG_VALUE ) &&
             ( StringFind( _Symbol, strRight ) != WRONG_VALUE )    )
            return( false );
      }
      return( true );
   }
   return( false );
}
//+------------------------------------------------------------------------------------+
// Function to Test Expiration during Tick Events
//+------------------------------------------------------------------------------------+
bool boolRestrictOnTick()
{
   if( boolRestrictions )
   {
      if( boolRestrictionsUnverified )
         return( boolRestrictOnInit() );
      if( boolRestrictExpiration && ( TimeCurrent() >= dtRestrictExpiration ) )
         return( boolRestrictAlert()  );
   }
   return( false );
}
// Function to Alert User of Licensing Restrictions and Remove Code from Execution
bool boolRestrictAlert()
{
   if( boolRestrictAlert )
      MessageBox( strRestrictAlertMessage, strRestrictAlertCaption, MB_ICONERROR );
   ExpertRemove();
   return( true );
}
//+------------------------------------------------------------------------------------+
//      Variables for Handling of Licensing Restrictions
//+------------------------------------------------------------------------------------+
bool
   boolRestrictExpiration     = false, // Set to true, to use an Experation Date
   boolRestrictAccountNumber  = false, // Set to true for Restricting by Account Number
   boolRestrictAccountName    = false, // Set to true for Restricting by Account Name
   boolRestrictAccountServer  = false, // Set to true for Restricting by Account Server
   boolRestrictAccountCompany = false, // Set to true for Restricting by Account Company
   boolRestrictDemoAccount    = false, // Set to true, to only allow Demo Accounts
   boolRestrictSymbols        = false, // Set to true, to only allow certain Symbols
   boolRestrictAlert          = true,  // Display Alert Message when Restrictions apply
   boolRestrictionsUnverified = false, // DO NOT CHANGE. For internal use only!
   boolRestrictions           = false; // DO NOT CHANGE. For internal use only!
datetime
   dtRestrictExpiration       = D'2017.03.31';  // Restricted by Expration Date
long
   longRestrictAccountNumber  = 123456789;      // Restricted by Account Number
string
   strRestrictAccountName     = "Client Name",  // Restricted by Account Name
   strRestrictAccountServer   = "Server Name",  // Restricted by Account Server
   strRestrictAccountCompany  = "Company Name", // Restricted by Account Company
   strRestrictSymbols[]       = { "EURUSD", "GBPJPY", "NZDCAD" }, // Restricted Symbols
   strRestrictAlertCaption    = "Restrictions", // Alert Message Box Caption
   strRestrictAlertMessage    =
      "ATTENTION! Due to Licensing Restrictions, code execution has been blocked!";
      // Message to be used when Restrictions have been detected
//+------------------------------------------------------------------------------------+

 
Fernando Carreiro:

No it is not specific enough to every user, because there are people with the same name all over the world! So use the other account information to make it more specific (see code below).

You said you wanted to extract the information via your EA running on a customer's machine. That is what I gave you! The customer already knows his own name and the name on his trading account! He does not need to extract it, but yes he can see it right under the Account names in MetaTrader's Navigator window.


Thank you very much for explaining and helping 🙏 I will examine it in detail

Reason: