T
T
timofeev_sergei2810932022-01-30 00:17:02
API
timofeev_sergei281093, 2022-01-30 00:17:02

MikroTik C# API authorization error?

There is a simple c# console program that knocks on MikroTik via API.
Before that, I had implemented something similar, only everything was written in visual studio 2010 and the version of router os was 6.43 and lower (I found and overcame the change in authorization type).
Now there is a problem - "login failure for user my_user from my_ip via api". IP services are configured correctly, the user and password are checked far and wide. IP=>firewall locked all the rules. In general, the standard methods "and am I not a fool" are checked. The API class is taken fresh from wiki.mikrotik. Version Router OS 6.48.4, MikroTik RB1100.
Here is the class authorization method:

public bool Login(string username, string password)
        {
            Send("/login", true);
            string hash = Read()[0].Split(new string[] { "ret=" }, StringSplitOptions.None)[1];
            Send("/login");
            Send("=name=" + username);
            Send("=response=00" + EncodePassword(password, hash), true);
            if (Read()[0] == "!done")
            {
                return true;
            }
            else
            {
                return false;
            }
        }

PS there is an API implementation in PHP and it works great.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
timofeev_sergei281093, 2022-03-01
@timofeev_sergei281093

Decided! The problem is in the crooked class in the official sources, or rather in the authorization method. The method posted there is deprecated
. Here is the correct method:

public bool Login(string username, string password)
    {
        Send("/login");
        Send("=name=" + username);
        Send("=password=" + password, true);
        if (Read()[0] == "!done")
        {
            return true;
        }
        else
        {
            return false;
        }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question