示例#1
0
        private void button_Click_1(object sender, RoutedEventArgs e)
        {
            db         a  = new db();
            UpdatePass up = new UpdatePass
            {
                Password    = pass1.Password,
                NewPassword = pass2.Password
            };

            a.A();
            string     login    = db.Login;
            SaltedHash password = new SaltedHash(up.Password);
            string     salt     = password.Salt;
            string     hash     = password.Hash;

            if (Validate.Valid(up))
            {
                if (a.Sign_in(login, up.Password))
                {
                    a.UpdatePass(salt, hash);
                    MessageBox.Show("Пароль изменен");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Вы ввели неверный пароль!");
                    pass1.Password = "";
                    pass2.Password = "";
                }
            }
        }
示例#2
0
文件: db.cs 项目: vitali-anku/4_sem
        public bool Sign_in(string login, string pass)
        {
            conn.Open();

            try
            {
                string zapros = string.Format("Select * from yuzer where login = @login");

                using (SqlCommand myCommand = new SqlCommand(zapros, conn))
                {
                    myCommand.CommandText = "Select * from yuzer where login = @login";
                    myCommand.Parameters.AddWithValue("@login", login);
                    myCommand.ExecuteNonQuery();
                    SqlDataReader myReader = myCommand.ExecuteReader();
                    if (myReader.HasRows)
                    {
                        while (myReader.Read())
                        {
                            Login           = myReader["login"].ToString();
                            Salt            = myReader["salt"].ToString();
                            Hash            = myReader["hash"].ToString();
                            Number_passport = myReader["number_passprort"].ToString();
                            Number_user     = (int)myReader["number_user"];
                        }
                        if (SaltedHash.Verify(Hash, pass, Salt))
                        {
                            o = true;
                        }
                        else
                        {
                            o = false;
                        }
                    }
                    else
                    {
                        o = false;
                    }
                }
            }

            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }

            conn.Close();
            return(o);
        }
示例#3
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            Registr reg = new Registr
            {
                Log             = Log.Text,
                FullName        = Nam.Text,
                NumberPassport  = Passp.Text,
                Password        = pass1.Password,
                PasswordConfirm = pass2.Password
            };

            db re = new db();

            try
            {
                if (Validate.Valid(reg))
                {
                    SaltedHash salt = new SaltedHash(reg.Password);

                    string hash = salt.Hash;
                    string sal  = salt.Salt;

                    if (re.Vald(reg.Log))
                    {
                        re.Reg(reg.Log, reg.FullName, sal, reg.NumberPassport, hash);
                        Sign_in ni = new Sign_in();
                        NavigationService.Navigate(ni);
                    }
                    else
                    {
                        MessageBox.Show("Пользователь с таким логином существует");
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show(ToString());
            }
        }