Advertisement
SHILY

Авторизация mail.ru

Jan 20th, 2021 (edited)
664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.72 KB | None | 0 0
  1. /*--------------------------------
  2.         Данные для запроса
  3. *///------------------------------
  4. string _account = "login:password"; // аккаунт через разделитель "login:pass" или "login;pass".
  5. string _proxy = "";
  6.  
  7. /*----------------------------------------------------
  8.         Авторизация майлру
  9. *///---------------------------------------------------
  10. string _login = String.Empty, _password = String.Empty;
  11. try
  12. {
  13.     _login = _account.Split(':', ';')[0];
  14.     _password = _account.Split(':', ';')[1];
  15.    
  16.     if (String.IsNullOrWhiteSpace(_login)) throw new Exception("Логин не указан");
  17.     if (String.IsNullOrWhiteSpace(_password)) throw new Exception("Пароль не указан");
  18.    
  19.     project.Profile.CookieContainer.Clear(); // очистка контейнера куков.
  20.    
  21.     string HttpResponse = ZennoPoster.HTTP.Request
  22.     (
  23.         ZennoLab.InterfacesLibrary.Enums.Http.HttpMethod.GET, "https://mail.ru/", "", "", _proxy, "UTF-8",
  24.         ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.BodyOnly, 20000, "", project.Profile.UserAgent, true, 5,
  25.         new String[]{},  "", false, false, project.Profile.CookieContainer
  26.     );
  27.     if (String.IsNullOrWhiteSpace(HttpResponse)) throw new Exception("HttpResponse пуст");
  28.  
  29.     string token = Regex.Match(HttpResponse, "((?<=CSRF:\").*?(?=\")|(?<=CSRF:\\ \").*?(?=\"))").Value; // парсинг токена для авторизации.
  30.    
  31.     if (String.IsNullOrWhiteSpace(token)) throw new Exception("token для авторизации не найден");
  32.    
  33.     /*Авторизация*/
  34.     HttpResponse = ZennoPoster.HTTP.Request
  35.     (
  36.         ZennoLab.InterfacesLibrary.Enums.Http.HttpMethod.POST, "https://auth.mail.ru/jsapi/auth",
  37.         $"login={ZennoLab.Macros.TextProcessing.UrlEncode(_login)}&password={ZennoLab.Macros.TextProcessing.UrlEncode(_password)}&saveauth=1&token={token}&project=e.mail.ru&_="
  38.         + Convert.ToString((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).Replace(",", "").Substring(0, 13),
  39.         "application/x-www-form-urlencoded", _proxy, "UTF-8",
  40.         ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.HeaderAndBody, 20000, "", project.Profile.UserAgent, true, 5,
  41.         new String[]
  42.         {
  43.             "Accept: */*",
  44.             "Origin: https://mail.ru",
  45.             "Referer: https://mail.ru/",
  46.             "Connection: keep-alive"
  47.         },
  48.         "", false, false, project.Profile.CookieContainer
  49.     );
  50.     if (Regex.IsMatch(HttpResponse, "(?<=\\{\"status\":\")ok.*?(?=\"})"))
  51.     {
  52.         project.Profile.Save($@"{project.Directory}\profiles\{_login}.zpprofile", true, true, true, true, true, true, true, true, true, new string[]{"PROXY"}); // сейв профиля.
  53.         project.SendInfoToLog($"{_login} | Успешная авторизация", true); // лог для zp.
  54.     }
  55.     else
  56.     {
  57.         /*Определение ошибки, если не вышло авторизоваться*/
  58.         if (!Regex.IsMatch(HttpResponse, "((?<=\\{\"status\":\")break.*?(?=\"})|(?<=\"status\":\")fail.*?(?=\"}))")) throw new Exception("Неизвестная ошибка авторизации");
  59.         if (Regex.IsMatch(HttpResponse, "(?<=\\{\"status\":\")break.*?(?=\"})")) throw new Exception("Требуется SMS подтверждение/Восстановление доступа");
  60.         if (Regex.IsMatch(HttpResponse, "(?<=\"status\":\")fail.*?(?=\"})")) throw new Exception("Не верный логин или пароль");
  61.     }
  62. }
  63. catch (Exception ex)
  64. {
  65.     project.SendWarningToLog(!String.IsNullOrWhiteSpace(_login) ? $"{_login} | {ex.Message}" : $"{ex.Message}", true);
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement