Beispiel #1
0
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            if (VaildateReg())
            {
                //Encrypt pass = new Encrypt();
                //string username = pass.ATOZ(txtUserAdd.Text);
                string email   = txtEmailAdd.Text;
                var    Website = txtSiteAdd.Text;
                //string password = pass.ATOZ(txtPassAdd.Text);
                CryptographyProcessor crypt = new CryptographyProcessor();

                salt = crypt.CreateSalt(10);
                var username = Cipher.Encrypt(txtPassAdd.Text, salt);
                var password = Cipher.Encrypt(txtUserAdd.Text, salt);

                //Decrypting method
                //var strDecrypted = Cipher.Decrypt(strEncryptred, salt);


                string queryString =
                    "SELECT AppData FROM StorageData INSERT INTO AppData (Username, Email, Password, UserLogin, Salting) " +
                    "VALUES (" + (string)username + ", " + (string)email + ", " + (string)password + ", " + GUI.UsernameLogin + ", " + (string)salt + ");";
                string connectionString =
                    "Data Source=LAPTOP-IRITE623;Initial Catalog=StorageData;Integrated Security=True";

                try
                {
                    using (SqlConnection sqlcon = new SqlConnection(connectionString))
                    {
                        sqlcon.Open();
                        SqlCommand sqlcmd = new SqlCommand("DataAdd", sqlcon);
                        sqlcmd.CommandType = CommandType.StoredProcedure;
                        sqlcmd.Parameters.AddWithValue("@Website", Website);
                        sqlcmd.Parameters.AddWithValue("@Username", username);
                        sqlcmd.Parameters.AddWithValue("@Email", email);
                        sqlcmd.Parameters.AddWithValue("@Password", password);
                        sqlcmd.Parameters.AddWithValue("@UserLogin", GUI.UsernameLogin);
                        sqlcmd.Parameters.AddWithValue("@Saltting", salt);

                        sqlcmd.ExecuteNonQuery();

                        WriteData();
                    }
                }
                catch
                {
                    MessageBox.Show("Failed to store data.");
                }
            }
            else
            {
            }
            //txtDisplay.Text +=
        }
Beispiel #2
0
        private void BtnLogin_Click(object sender, EventArgs e)
        {
            if (ValidateLogin())
            {
                string connectionString = "Data Source=LAPTOP-IRITE623;Initial Catalog=Users;Integrated Security=True";
                string queryString      =
                    "SELECT Username, Password, Saltting FROM dbo.Data;";
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    SqlCommand command = new SqlCommand(
                        queryString, connection);
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    try
                    {
                        string username = txtUser.Text;

                        UsernameLogin = username;
                        while (reader.Read())
                        {
                            //var passwordd = new String(reader[1].Where(Char.IsDigit).ToArray());
                            //reader[0], reader[1]));
                            //reader.Read();
                            //Encrypt pass = new Encrypt();
                            //string username = pass.ATOZ(txtUser.Text);
                            //string password = pass.ATOZ(txtPass.Text);

                            //count++;

                            CryptographyProcessor crypt = new CryptographyProcessor();
                            //string password = crypt.GenerateHash(txtPass.Text, salt);


                            if (username == (string)reader[0] && crypt.AreEqual(txtPass.Text, (string)reader[1], (string)reader[2]))
                            {
                                this.Hide();
                                frmMain main = new frmMain();
                                main.Show();
                                break;
                            }
                        }
                    }
                    finally
                    {
                        reader.Close();
                    }
                }
            }
        }
Beispiel #3
0
        private void BtnReg_Click(object sender, EventArgs e)
        {
            string connectionStringg = "Data Source=LAPTOP-IRITE623;Initial Catalog=Users;Integrated Security=True";
            string queryStringg      =
                "SELECT Username, Password, Saltting FROM dbo.Data;";

            using (SqlConnection connection = new SqlConnection(connectionStringg))
            {
                SqlCommand command = new SqlCommand(
                    queryStringg, connection);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                try
                {
                    checkUser = 0;

                    while (reader.Read())
                    {
                        string readerr = (string)reader[0];
                        if (txtUserReg.Text.ToLower() != readerr.ToLower())
                        {
                            checkUser++;
                        }
                    }
                }
                finally
                {
                    reader.Close();
                }
            }


            if (GUI.count == checkUser)
            {
                if (VaildateReg())
                {
                    //Encrypt pass = new Encrypt();
                    //string username = pass.ATOZ(txtUserReg.Text);
                    //string email = txtEmailReg.Text;
                    //string password = pass.ATOZ(txtPassReg.Text);z

                    CryptographyProcessor crypt = new CryptographyProcessor();
                    string salt     = crypt.CreateSalt(10);
                    string password = crypt.GenerateHash(txtPassReg.Text, salt);
                    string username = txtUserReg.Text;
                    string email    = txtEmailReg.Text;

                    string queryString =
                        "SELECT Data FROM Users INSERT INTO Data (Username, Email, Password, Admin, Saltting) " +
                        "VALUES (" + (string)username + ", " + (string)email + ", " + (string)password + ", " + 0 + ", " + salt + ");";
                    string connectionString = "Data Source=LAPTOP-IRITE623;Initial Catalog=Users;Integrated Security=True";

                    try
                    {
                        using (SqlConnection sqlcon = new SqlConnection(connectionString))
                        {
                            sqlcon.Open();
                            SqlCommand sqlcmd = new SqlCommand("UserADD", sqlcon);
                            sqlcmd.CommandType = CommandType.StoredProcedure;
                            sqlcmd.Parameters.AddWithValue("@Username", username);
                            sqlcmd.Parameters.AddWithValue("@Email", email);
                            sqlcmd.Parameters.AddWithValue("@Password", password);
                            sqlcmd.Parameters.AddWithValue("@Admin", 0);
                            sqlcmd.Parameters.AddWithValue("@Saltting", salt);

                            sqlcmd.ExecuteNonQuery();
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Failed to store user");
                    }


                    GUI login = new GUI();
                    this.Hide();
                    login.Show();
                }
                else
                {
                }
            }
            else
            {
                MessageBox.Show("Name isn't available!");
            }
        }