Exemplo n.º 1
0
        // checks hte checksum of the current file to database file
        public bool verifyCheckSum(byte[] checksum, int userid)
        {
            //create dataset and table adapter objects
            edproj1 ed = new edproj1();

            edproj1TableAdapters.EncryptedTableAdapter uAdapter =
                new edproj1TableAdapters.EncryptedTableAdapter();

            // get info from table adaptors
            uAdapter.Fill(ed.Encrypted);
            // datarow for encrypted
            DataRow[] dr = ed.Encrypted.Select();

            bool result = false;

            if (checksum == (byte[])dr[userid]["FileHash"])
            {
                result = true;
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// When the user presses this button, a copy of the User table is made and each entry is
        /// retrieved and placed in a datarow[]. The inputted username and password are compared
        /// to each entry in the table to check if the username is unique. If it is then a message
        /// is displayed to the user and the table is updated with the new account info.
        /// </summary>
        private void btnSignUp_Click(object sender, EventArgs e)
        {
            //new user object will store the inputted username and password
            //the values will be compared to the table records
            User user = new User();

            user.UserName = txtName.Text;
            user.Password = txtPass.Text;
            user.Email    = txtEmail.Text;//can be null
            bool result = false;

            //there must be a username and password for you to register
            if (user.UserName == "" || user.Password == "")
            {
                MessageBox.Show("No empty boxes", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //dataset and table adapter for connecting, retrieving, and updating from database
                edproj1 ed = new edproj1();
                edproj1TableAdapters.UserTableAdapter uAdapter =
                    new edproj1TableAdapters.UserTableAdapter();
                //get info from table adaptors
                uAdapter.Fill(ed.User);
                //dr contains all record from table (select * from user)
                DataRow[] dr = ed.User.Select();
                //loop through each record in the table and compare the usernames and passwords
                //to the user object's attributes
                for (int i = 0; i < dr.Length; i++)
                {
                    string dbUser = (string)dr[i]["Name"];
                    string dbPass = (string)dr[i]["Password"];

                    //if true is returned, then the given username is in the table already
                    //and not available, else it is and registration proceeds
                    if (user.UserName == dbUser)
                    {
                        result = false;
                        break;
                    }
                    else
                    {
                        result = true;
                    }
                }
                // validate email
                try
                {
                    MailAddress m = new MailAddress(user.Email);
                }
                catch (FormatException)
                {
                    MessageBox.Show("Invalid email!", "Error"
                                    , MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                //if there is a match with usernames then an error is returned and user prompted again
                //if no match ie. the username is unique then it gets added to the user table
                //user is then sent back to the login and can try to login with their new account
                if (result == false)
                {
                    MessageBox.Show("Username taken, please try a different one", "Error"
                                    , MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    //uRow contains new user info and will be used to update the real database
                    edproj1.UserRow uRow = ed.User.NewUserRow();
                    uRow.Name     = user.UserName;
                    uRow.Password = user.Password;
                    uRow.Email    = user.Email;

                    //add new row to the local cache
                    ed.User.Rows.Add(uRow);
                    //update the real database with the new row
                    uAdapter.Update(ed.User);
                    MessageBox.Show("Registration Successful", "Success"
                                    , MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// authenticates the user and allows access to the rest of the application
        /// </summary>
        private void btnLogin_Click(object sender, EventArgs e)
        {
            User user = new User();

            user.UserName = txtUsername.Text;
            user.Password = txtPassword.Text;
            bool result = false;

            if (user.UserName == "" || user.Password == "")
            {
                MessageBox.Show("No empty boxes", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            //create dataset and table adapter objects
            edproj1 ed = new edproj1();

            edproj1TableAdapters.UserTableAdapter uAdapter =
                new edproj1TableAdapters.UserTableAdapter();

            //get info from table adaptors
            uAdapter.Fill(ed.User);

            DataRow[] dr     = ed.User.Select();
            int       userid = 0;

            //compare given username and password to every entry in the table
            for (int i = 0; i < dr.Length; i++)
            {
                string dbUser = (string)dr[i]["Name"];
                string dbPass = (string)dr[i]["Password"];

                //compare the given username and password with the records in the table
                if (user.validate(dbUser, dbPass))
                {
                    result = true;
                    userid = i;
                    break;
                }
                else
                {
                    result = false;
                }
            }

            //if there is a match the validate method will return true and login is successful
            //otherwise there is no match and the user will be asked to enter again
            if (result)
            {
                MessageBox.Show("Login SuccessFul", "Success!"
                                , MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                //transfer to next web form
                Form1 f = new Form1(userid);
                this.Hide();
                f.ShowDialog();
            }
            else
            {
                MessageBox.Show("Login failed, check your username and password and try again", "Access Denied"
                                , MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }