Beispiel #1
0
        public bool LogInProcess(ref int id, string login, string password)
        /* Sign in - true if you can */
        {
            HashPassword hsp = new HashPassword();

            foreach (UserLoginAndPassword user in userLoginAndPassword)
            {
                if (user.GetLogin() == login)
                {
                    string passwordDataBase = user.GetPassword();
                    string passwordTextBox  = hsp.GenerateSHA256Hash(password, user.GetSalt());
                    if (user.GetPassword() == passwordTextBox)
                    {
                        id = user.GetId();
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #2
0
        /*   private int GetUserId()
         *  {
         *      UserData user = new UserData();
         *
         *      SqlConnection con = new SqlConnection(@"Data Source = (local)\SQLEXPRESS; Initial Catalog = SysWal; Integrated Security = True");
         *      // string command = "select * from UserData where UserId =" + id;
         *      string command = "SELECT @@IDENTITY";
         *      SqlCommand myCommand = new SqlCommand(command, con);
         *
         *      con.Open();
         *      SqlDataReader myReader = myCommand.ExecuteReader();
         *
         *
         *      return id;
         *  }
         */


        private void AddNewUser(ref bool check)
        {
            HashPassword      hsp      = new HashPassword();
            ReadAndUpdateData r        = new ReadAndUpdateData();
            UserData          userData = new UserData();
            string            salt     = hsp.CreateSalt(10);

            user = CreateUser(ref check, salt);
            if (check == true)
            {
                con = new SqlConnection(@"Data Source=(local)\SQLEXPRESS;Initial Catalog=SysWal;Integrated Security=True");
                con.Open();

                cmd = new SqlCommand("INSERT INTO UserData (login, password, name, surname, PESEL, accountNo, email, salt) values (@login, @password, @name, @surname, @PESEL, @accountNo, @email, @salt)", con);
                cmd.Parameters.AddWithValue("@login", user.GetLogin());
                cmd.Parameters.AddWithValue("@password", hsp.HashUserPassword(user.GetPassword(), salt));
                cmd.Parameters.AddWithValue("@name", user.GetName());
                cmd.Parameters.AddWithValue("@surname", user.GetSurname());
                cmd.Parameters.AddWithValue("@PESEL", user.GetPESEL());
                cmd.Parameters.AddWithValue("@accountNo", user.GetAccountNo());
                cmd.Parameters.AddWithValue("@email", user.GetEmail());
                cmd.Parameters.AddWithValue("@salt", user.GetSalt());

                cmd.ExecuteNonQuery();

                string     command   = "SELECT MAX(UserID)FROM UserData";
                SqlCommand myCommand = new SqlCommand(command, con);
                int        id        = (int)myCommand.ExecuteScalar();


                SendMail sm = new SendMail();
                MessageBox.Show(sm.MailSend(user.GetEmail(), user.GetName()));
                r.CreateWallet(id);
                MessageBox.Show("Rejestracja zakończona pomyslnie!");
            }
            else
            {
                MessageBox.Show("Niepoprawne Dane!");
            }
        }
Beispiel #3
0
        private UserData CreateUser(ref bool check, string salt)
        {
            // UserData user(loginText.Text, passwordText.Text, nameText.Text, surnameText.Text, PESELText.Text, accountNoText.Text, emailText.Text, 0)
            user = new UserData();
            HashPassword hsp    = new HashPassword();
            bool         check2 = true;

            user.SetLogin(loginText.Text);
            user.SetPassword(passwordText.Text);
            user.SetName(nameText.Text);
            user.SetSurname(surnameText.Text);
            user.SetPESEL(PESELText.Text);
            user.SetAccountNo(accountNoText.Text);
            user.SetEmail(emailText.Text);

            if (user.CheckLogin() == false)
            {
                loginText.BackColor = Color.Red; check2 = false;
            }
            else
            {
                loginText.BackColor = Color.White;
            }
            if (user.CheckPassword() == false)
            {
                passwordText.BackColor = Color.Red; check2 = false;
            }
            else
            {
                passwordText.BackColor = Color.White;
            }
            if (user.CheckName() == false)
            {
                nameText.BackColor = Color.Red; check2 = false;
            }
            else
            {
                nameText.BackColor = Color.White;
            }
            if (user.CheckSurname() == false)
            {
                surnameText.BackColor = Color.Red; check2 = false;
            }
            else
            {
                surnameText.BackColor = Color.White;
            }
            if (user.CheckPESEL() == false)
            {
                PESELText.BackColor = Color.Red; check2 = false;
            }
            else
            {
                PESELText.BackColor = Color.White;
            }
            if (user.CheckAccountNo() == false)
            {
                accountNoText.BackColor = Color.Red; check2 = false;
            }
            else
            {
                accountNoText.BackColor = Color.White;
            }
            if (user.CheckEmail() == false)
            {
                emailText.BackColor = Color.Red; check2 = false;
            }
            else
            {
                emailText.BackColor = Color.White;
            }
            if (check2 == true)
            {
                user.SetSalt(salt);
                check = true;
            }
            return(user);
        }