// Decompiled with JetBrains decompiler
// Type: FileCash_v3._0.auth
// Assembly: FileCash_v3.0, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 1DECC99D-34C5-4E02-A85D-DC744B5C555A
// Assembly location: C:\Users\Administrateur\Downloads\Virusshare-00001-msil\Constructor.MSIL.ArchSMS.a-33cc8dceb24ed9df287e1f92d02773477af42b8d2b6de53a45bb9b5a3ead070b.exe

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Windows.Forms;
using System.Xml;

namespace FileCash_v3._0
{
  public class auth : Form
  {
    private IContainer components;
    private Button login;
    private GroupBox groupBox1;
    private LinkLabel linkLabel1;
    private CheckBox SaveMyLP;
    private TextBox PasswordEbox;
    private Label label2;
    private Label label1;
    private ComboBox LoginEbox;
    private FileCash FCashObj = new FileCash();
    private XmlDocument xmldoc;
    private XmlNodeList xmlnode;

    protected override void Dispose(bool disposing)
    {
      if (disposing && this.components != null)
        this.components.Dispose();
      base.Dispose(disposing);
    }

    private void InitializeComponent()
    {
      ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (auth));
      this.login = new Button();
      this.groupBox1 = new GroupBox();
      this.LoginEbox = new ComboBox();
      this.linkLabel1 = new LinkLabel();
      this.SaveMyLP = new CheckBox();
      this.PasswordEbox = new TextBox();
      this.label2 = new Label();
      this.label1 = new Label();
      this.groupBox1.SuspendLayout();
      this.SuspendLayout();
      this.login.Location = new Point(166, 111);
      this.login.Name = "login";
      this.login.Size = new Size(153, 23);
      this.login.TabIndex = 4;
      this.login.Text = "Войти в программу";
      this.login.UseVisualStyleBackColor = true;
      this.login.Click += new EventHandler(this.login_Click);
      this.groupBox1.Controls.Add((Control) this.LoginEbox);
      this.groupBox1.Controls.Add((Control) this.linkLabel1);
      this.groupBox1.Controls.Add((Control) this.SaveMyLP);
      this.groupBox1.Controls.Add((Control) this.PasswordEbox);
      this.groupBox1.Controls.Add((Control) this.label2);
      this.groupBox1.Controls.Add((Control) this.label1);
      this.groupBox1.Controls.Add((Control) this.login);
      this.groupBox1.Location = new Point(5, 12);
      this.groupBox1.Name = "groupBox1";
      this.groupBox1.Size = new Size(326, 163);
      this.groupBox1.TabIndex = 1;
      this.groupBox1.TabStop = false;
      this.groupBox1.Text = "Данные для авторизации";
      this.LoginEbox.FormattingEnabled = true;
      this.LoginEbox.Location = new Point(95, 31);
      this.LoginEbox.Name = "LoginEbox";
      this.LoginEbox.Size = new Size(224, 21);
      this.LoginEbox.TabIndex = 1;
      this.LoginEbox.SelectedIndexChanged += new EventHandler(this.LoginEbox_SelectedIndexChanged);
      this.linkLabel1.ActiveLinkColor = Color.Black;
      this.linkLabel1.AutoSize = true;
      this.linkLabel1.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Bold, GraphicsUnit.Point, (byte) 204);
      this.linkLabel1.LinkColor = Color.Black;
      this.linkLabel1.Location = new Point(72, 143);
      this.linkLabel1.Name = "linkLabel1";
      this.linkLabel1.Size = new Size(247, 13);
      this.linkLabel1.TabIndex = 6;
      ((Label) this.linkLabel1).TabStop = true;
      this.linkLabel1.Text = "Получить учетную запись (Регистрация)";
      this.linkLabel1.LinkClicked += new LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
      this.SaveMyLP.AutoSize = true;
      this.SaveMyLP.Location = new Point(95, 88);
      this.SaveMyLP.Name = "SaveMyLP";
      this.SaveMyLP.Size = new Size(164, 17);
      this.SaveMyLP.TabIndex = 3;
      this.SaveMyLP.Text = "Сохранить учетные данные";
      this.SaveMyLP.UseVisualStyleBackColor = true;
      this.PasswordEbox.Location = new Point(95, 62);
      this.PasswordEbox.Name = "PasswordEbox";
      this.PasswordEbox.PasswordChar = '*';
      this.PasswordEbox.Size = new Size(224, 20);
      this.PasswordEbox.TabIndex = 2;
      this.label2.AutoSize = true;
      this.label2.Location = new Point(22, 62);
      this.label2.Name = "label2";
      this.label2.Size = new Size(48, 13);
      this.label2.TabIndex = 2;
      this.label2.Text = "Пароль:";
      this.label1.AutoSize = true;
      this.label1.Location = new Point(22, 34);
      this.label1.Name = "label1";
      this.label1.Size = new Size(41, 13);
      this.label1.TabIndex = 1;
      this.label1.Text = "Логин:";
      this.AutoScaleDimensions = new SizeF(6f, 13f);
      this.AutoScaleMode = AutoScaleMode.Font;
      this.ClientSize = new Size(336, 177);
      this.Controls.Add((Control) this.groupBox1);
      this.FormBorderStyle = FormBorderStyle.FixedSingle;
      this.Icon = (Icon) componentResourceManager.GetObject("$this.Icon");
      this.MaximizeBox = false;
      this.MinimizeBox = false;
      this.Name = nameof (auth);
      this.SizeGripStyle = SizeGripStyle.Hide;
      this.Text = "Авторизация";
      this.groupBox1.ResumeLayout(false);
      this.groupBox1.PerformLayout();
      this.ResumeLayout(false);
    }

    public auth()
    {
      this.InitializeComponent();
      if (!File.Exists(this.FCashObj.SavedPassXml) || !(File.ReadAllText(this.FCashObj.SavedPassXml, Encoding.UTF8) != ""))
        return;
      this.xmldoc = new XmlDocument();
      this.xmldoc.Load(this.FCashObj.SavedPassXml);
      this.xmlnode = this.xmldoc.GetElementsByTagName("acc");
      for (int i = 0; i < this.xmlnode.Count; ++i)
        this.LoginEbox.Items.Add((object) this.xmlnode[i].ChildNodes.Item(0).InnerText);
      this.LoginEbox.SelectedIndex = 0;
      this.PasswordEbox.Text = this.xmlnode[0].ChildNodes.Item(1).InnerText;
    }

    private void login_Click(object sender, EventArgs e)
    {
      this.FCashObj.GetSID(this.FCashObj.DomainIP + "/start.php");
      if (this.FCashObj.SID == null)
        return;
      this.FCashObj.HDD_Serial = "";
      this.FCashObj.OS_Version = "3.3";
      if (new Regex("^[A-Za-z0-9_]{2,30}$").IsMatch(this.LoginEbox.Text) && this.PasswordEbox.Text.Length >= 4)
      {
        this.FCashObj.Login = this.LoginEbox.Text;
        this.FCashObj.Password = this.PasswordEbox.Text;
        string input1 = this.FCashObj.SendPost(this.FCashObj.DomainIP + "/auth.php", "sid=" + this.FCashObj.SID + "&login=" + this.FCashObj.Login + "&password=" + HttpUtility.UrlEncode(this.FCashObj.Password) + "&hardware=" + this.FCashObj.HDD_Serial + "&version=" + this.FCashObj.OS_Version);
        if (input1 == null)
          return;
        switch (input1)
        {
          case "erAut":
            int num1 = (int) MessageBox.Show("Не правильный логин или пароль!", "Ошибка авторизации", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            break;
          case "erAutSId":
          case "erAutId":
          case "erAutVer":
            int num2 = (int) MessageBox.Show("Произошла ошибка при авторизации!", "Ошибка авторизации", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            break;
          default:
            string text = (string) null;
            string str = (string) null;
            Match match1 = new Regex("msgAutOk=\"([0-9]*)\"").Match(input1);
            if (match1.Groups[1] != null)
              this.FCashObj.USERID = Convert.ToInt32(match1.Groups[1].ToString());
            Match match2 = new Regex("msgtextau=\"(.*)\",").Match(input1);
            if (match2.Groups[1] != null)
              text = match2.Groups[1].ToString();
            Match match3 = new Regex("lastauth=\"(.*)\"").Match(input1);
            if (match3.Groups[1] != null)
              this.FCashObj.LastAuth = match3.Groups[1].ToString();
            Match match4 = new Regex("closeau=\"(.*)\"").Match(input1);
            if (match4.Groups[1].ToString() == "1")
              str = match4.Groups[1].ToString();
            if (text != "")
            {
              int num3 = (int) MessageBox.Show(text);
            }
            if (str != null)
              Application.Exit();
            if (this.SaveMyLP.Checked)
            {
              if (!Directory.Exists(this.FCashObj.SavedPassFolder))
                Directory.CreateDirectory(this.FCashObj.SavedPassFolder);
              FileStream fileStream = File.Open(this.FCashObj.SavedPassXml, FileMode.OpenOrCreate, FileAccess.ReadWrite);
              fileStream.Close();
              bool flag = false;
              string input2 = File.ReadAllText(this.FCashObj.SavedPassXml, Encoding.UTF8);
              if (input2 != "")
              {
                this.xmlnode = this.xmldoc.GetElementsByTagName("acc");
                for (int i = 0; i < this.xmlnode.Count; ++i)
                {
                  if (this.xmlnode[i].ChildNodes.Item(0).InnerText.ToLower() == this.LoginEbox.Text.ToLower())
                  {
                    if (this.PasswordEbox.Text != this.xmlnode[i].ChildNodes.Item(1).InnerText)
                    {
                      input2 = Regex.Replace(input2, "<uname>" + this.xmlnode[i].ChildNodes.Item(0).InnerText + "</uname><sec>" + this.xmlnode[i].ChildNodes.Item(1).InnerText + "</sec>", "<uname>" + this.LoginEbox.Text.ToLower() + "</uname><sec>" + this.PasswordEbox.Text + "</sec>", RegexOptions.IgnoreCase);
                      fileStream = File.Open(this.FCashObj.SavedPassXml, FileMode.Open, FileAccess.Write);
                      StreamWriter streamWriter = new StreamWriter((Stream) fileStream, Encoding.UTF8);
                      streamWriter.Write(input2);
                      streamWriter.Flush();
                      fileStream.Close();
                    }
                    flag = true;
                    break;
                  }
                }
              }
              else
                input2 = "<all>";
              if (!flag)
              {
                fileStream = File.Open(this.FCashObj.SavedPassXml, FileMode.Open, FileAccess.Write);
                StreamWriter streamWriter = new StreamWriter((Stream) fileStream, Encoding.UTF8);
                streamWriter.WriteLine(input2.Replace("</all>", "") + "<acc><uname>" + this.LoginEbox.Text.ToLower() + "</uname><sec>" + this.PasswordEbox.Text + "</sec></acc></all>");
                streamWriter.Flush();
              }
              fileStream.Close();
            }
            this.Hide();
            new Form1(ref this.FCashObj).Show();
            break;
        }
      }
      else
      {
        int num = (int) MessageBox.Show("Укажите имя пользователя и пароль", "Ошибка авторизации", MessageBoxButtons.OK, MessageBoxIcon.Hand);
      }
    }

    private void LoginEbox_SelectedIndexChanged(object sender, EventArgs e) => this.PasswordEbox.Text = this.xmlnode[this.LoginEbox.SelectedIndex].ChildNodes.Item(1).InnerText;

    private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) => Process.Start("http://ccdev1.ru/reg.php");
  }
}
