Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            profile user;

            user.name     = textBox1.Text;
            user.password = textBox2.Text;
            user.hashIter = 0;
            string     hashedPassword = "";
            ActSelForm newForm        = new ActSelForm(user.name);

            if (ActSelForm.userExists)
            {
                if (ActSelForm.isFirstAuthF2)
                {
                    textBox1.Text = "";
                    textBox2.Text = "";
                    this.Hide();
                    newForm.Owner = this;
                    newForm.Show();
                }
                else
                {
                    user.hashIter  = ActSelForm.getHashIterNumber();
                    hashedPassword = user.password;
                    for (var i = 0; i < user.hashIter - 1; i++)
                    {
                        using (SHA512 shaM = new SHA512Managed())
                        {
                            hashedPassword = Encoding.UTF8.GetString(shaM.ComputeHash(Encoding.UTF8.GetBytes(hashedPassword)));
                        }
                    }
                    if (ActSelForm.checkHash(hashedPassword))
                    {
                        textBox1.Text = "";
                        textBox2.Text = "";
                        this.Hide();
                        newForm.Owner = this;
                        newForm.Show();
                    }
                    else
                    {
                        label3.Text = "Неверный пароль";
                        cntFails++;
                    }
                }
            }
            else
            {
                label3.Text = "Данного пользователя не существует";
            }
            if (cntFails == 2)
            {
                Close();
            }
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            bool   fLet = false;
            bool   fSym = false;
            bool   fPun = false;
            string hashedPassword;

            if (isFirstAuthF3)
            {
                if (textBox1.Text.Length >= 8)
                {
                    if (textBox1.Text == textBox2.Text)
                    {
                        hashedPassword  = ActSelForm.initList(textBox1.Text);
                        userF3.password = hashedPassword;
                        userF3.hashIter = ActSelForm.defaultIterNum;
                        pswChanged      = true;
                    }
                    else
                    {
                        label5.Text = "Пароли не совпадают";
                    }
                }
                else
                {
                    label5.Text = "Длина пароля меньше 8 символов";
                }
            }
            else
            {
                hashedPassword = textBox3.Text;
                for (var i = 0; i < userF3.hashIter; i++)
                {
                    using (SHA512 shaM = new SHA512Managed())
                    {
                        hashedPassword = Encoding.UTF8.GetString(shaM.ComputeHash(Encoding.UTF8.GetBytes(hashedPassword)));
                    }
                }
                // Удаляем из захешированной фразы лишние символы, которые мешают считыванию
                hashedPassword = hashedPassword.Replace(" ", "");
                hashedPassword = hashedPassword.Replace("\n", "");
                hashedPassword = hashedPassword.Replace("\t", "");
                hashedPassword = hashedPassword.Replace("\r", "");

                if (hashedPassword == userF3.password)
                {
                    if (textBox1.Text.Length >= 8)
                    {
                        if (textBox1.Text == textBox2.Text)
                        {
                            hashedPassword = ActSelForm.initList(textBox1.Text);

                            userF3.password = hashedPassword;
                            userF3.hashIter = ActSelForm.defaultIterNum;
                            pswChanged      = true;
                        }
                        else
                        {
                            label5.Text = "Пароли не совпадают";
                        }
                    }
                    else
                    {
                        label5.Text = "Длина пароля меньше 8 символов";
                    }
                }
                else
                {
                    label4.Text = "Неверно введен старый пароль";
                }
            }

            dataBase.dBase[ind] = userF3;
            if (pswChanged)
            {
                using (StreamWriter sw = new StreamWriter(@"log.txt", true))
                {
                    sw.WriteLine(DateTime.Now + " " + "Пароль изменен");
                }
                Close();
            }
        }
Example #3
0
 private void button1_Click(object sender, EventArgs e)
 {
     foreach (profile user in dataBase.dBase)
     {
         if (user.name.Equals(textBox1.Text.ToString()))
         {
             if (user.is_blocked)
             {
                 label3.Text = "Пользователь " + user.name + " заблокирован";
                 break;
             }
             else
             {
                 if (user.password == "")
                 {
                     ActSelForm newForm = new ActSelForm(user, true);
                     newForm.Owner = this;
                     textBox1.Text = "";
                     textBox2.Text = "";
                     label3.Text   = "";
                     this.Hide();
                     newForm.Show();
                     break;
                 }
                 else if (Crypter.DecryptPswd(user.password) == textBox2.Text)
                 {
                     ActSelForm newform = new ActSelForm(user, false);
                     newform.Owner = this;
                     textBox1.Text = "";
                     textBox2.Text = "";
                     label3.Text   = "";
                     this.Hide();
                     newform.Show();
                     break;
                 }
                 else
                 {
                     if (user.name == prevName)
                     {
                         cntFails++;
                     }
                     else
                     {
                         prevName = user.name;
                         cntFails = 0;
                     }
                     label3.Text = "Неверный пароль";
                     break;
                 }
             }
         }
         else
         {
             label3.Text = "Такого пользователя не существует";
         }
     }
     if (cntFails == 2)
     {
         Close();
     }
 }