コード例 #1
0
ファイル: ChgPswdForm.cs プロジェクト: yozice/AuthProgram
        private void button1_Click(object sender, EventArgs e)
        {
            bool fLet = false;
            bool fSym = false;
            bool fPun = false;

            if (isFirstAuthF3)
            {
                if (userF3.is_restricted)
                {
                    if (textBox1.Text.Length >= 8)
                    {
                        foreach (char c in textBox1.Text)
                        {
                            if (char.IsLetter(c))
                            {
                                fLet = true;
                            }
                            else if (char.IsSymbol(c))
                            {
                                fSym = true;
                            }
                            else if (char.IsPunctuation(c))
                            {
                                fPun = true;
                            }
                        }

                        if (fLet && fSym && fPun)
                        {
                            if (textBox1.Text == textBox2.Text)
                            {
                                userF3.password  = Crypter.EncryptPswd(textBox1.Text);
                                userF3.len_pswrd = textBox1.Text.Length;
                                pswChanged       = true;
                            }
                            else
                            {
                                label5.Text = "Пароли не совпадают";
                            }
                        }
                        else
                        {
                            label5.Text = "Необходимо использовать символы: a-z, A-Z \n+-*/=,.!?-():;\"";
                        }
                    }
                    else
                    {
                        label5.Text = "Длина пароля меньше 8 символов";
                    }
                }
                else
                {
                    if (textBox1.Text == textBox2.Text)
                    {
                        userF3.password  = Crypter.EncryptPswd(textBox1.Text);
                        userF3.len_pswrd = textBox1.Text.Length;
                        pswChanged       = true;
                    }
                    else
                    {
                        label5.Text = "Пароли не совпадают";
                    }
                }
            }
            else
            {
                if (textBox3.Text == Crypter.DecryptPswd(userF3.password))
                {
                    if (userF3.is_restricted)
                    {
                        if (textBox1.Text.Length >= 8)
                        {
                            foreach (char c in textBox1.Text)
                            {
                                if (char.IsLetter(c))
                                {
                                    fLet = true;
                                }
                                else if (char.IsSymbol(c))
                                {
                                    fSym = true;
                                }
                                else if (char.IsPunctuation(c))
                                {
                                    fPun = true;
                                }
                            }

                            if (fLet && fSym && fPun)
                            {
                                if (textBox1.Text == textBox2.Text)
                                {
                                    userF3.password  = Crypter.EncryptPswd(textBox1.Text);
                                    userF3.len_pswrd = textBox1.Text.Length;
                                    pswChanged       = true;
                                }
                                else
                                {
                                    label5.Text = "Пароли не совпадают";
                                }
                            }
                            else
                            {
                                label5.Text = "Необходимо использовать символы: a-z, A-Z \n+-*/=,.!?-():;\"";
                            }
                        }
                        else
                        {
                            label5.Text = "Длина пароля меньше 8 символов";
                        }
                    }
                    else
                    {
                        if (textBox1.Text == textBox2.Text)
                        {
                            userF3.password  = Crypter.EncryptPswd(textBox1.Text);
                            userF3.len_pswrd = textBox1.Text.Length;
                            pswChanged       = true;
                        }
                        else
                        {
                            label5.Text = "Пароли не совпадают";
                        }
                    }
                }
                else
                {
                    label4.Text = "Неверно введен старый пароль";
                }
            }

            int ind = -1;

            foreach (profile user in dataBase.dBase)
            {
                ind++;
                if (user.name == userF3.name)
                {
                    break;
                }
            }
            dataBase.dBase[ind] = userF3;
            if (pswChanged)
            {
                Close();
            }
        }
コード例 #2
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();
     }
 }