protected void btnLogin_Click(object sender, EventArgs e)
        {
            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                //create user object
                User objU = new User();

                //get salt value for this username
                String Username = txtUsername.Text;

                objU = (from u in db.Users where u.Username == Username select u).FirstOrDefault();

                //find match for username
                if (objU != null)
                {
                    String salt = objU.Salt;

                    //salt and hash plain text pw
                    String password = txtPassword.Text;
                    String pass_and_salt = password + salt;

                    // Create a new instance of the hash crypto service provider.
                    HashAlgorithm hashAlg = new SHA256CryptoServiceProvider();

                    // Convert the data to hash to an array of Bytes.
                    byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(pass_and_salt);

                    // Compute the Hash. This returns an array of Bytes.
                    byte[] bytHash = hashAlg.ComputeHash(bytValue);

                    // Optionally, represent the hash value as a base64-encoded string,
                    // For example, if you need to display the value or transmit it over a network.
                    string base64 = Convert.ToBase64String(bytHash);

                    //check if the passwords match
                    if (objU.Password == base64)
                    {

                        //store identity in session obj
                        Session["UserID"] = objU.UserID;
                        Session["Name"] = objU.Name;

                        //redirect to standings page
                        Response.Redirect("standings.aspx");

                    }
                    else
                    {
                        lblError.Text = "Invalid Login";
                    }
                }
                else
                {
                    lblError.Text = "Invalid Login";
                }

            }
        }
        protected void GetTeams()
        {
            //connect and get list of teams
            using (DefaultConnection db = new DefaultConnection())
            {
                var teams = from t in db.Teams
                            select t;

                //binding the teams query to the grid
                grdTeams.DataSource = teams.ToList();
                grdTeams.DataBind();
            }
        }
        protected void grdTeams_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //look for the id to be deleted
            Int32 TeamID = Convert.ToInt32(grdTeams.DataKeys[e.RowIndex].Values["TeamID"]);

            //connect to db
            using (DefaultConnection db = new DefaultConnection())
            {
                Team team = (from t in db.Teams
                             where t.TeamID == TeamID
                             select t).FirstOrDefault();
                //delete record
                db.Teams.Remove(team);
                db.SaveChanges();

                GetTeams();
            }
        }
Example #4
0
        protected void grdTeams_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //look for the id to be deleted
            Int32 TeamID = Convert.ToInt32(grdTeams.DataKeys[e.RowIndex].Values["TeamID"]);

            //connect to db
            using (DefaultConnection db = new DefaultConnection())
            {
                Team team = (from t in db.Teams
                             where t.TeamID == TeamID
                             select t).FirstOrDefault();
                //delete record
                db.Teams.Remove(team);
                db.SaveChanges();

                GetTeams();
            }
        }
Example #5
0
        protected void GetTeam()
        {
            //look up selected team and fill data in the form
            using (DefaultConnection db = new DefaultConnection())
            {
                Int32 TeamID = Convert.ToInt32(Request.QueryString["TeamID"]);

                //look up team
                Team team = (from t in db.Teams where t.TeamID == TeamID select t).FirstOrDefault();

                //fill data to form
                txtTeam.Text                  = team.TeamName;
                txtWins.Text                  = team.Wins.ToString();
                txtLosses.Text                = team.Losses.ToString();
                txtRunsScored.Text            = team.RunsScored.ToString();
                txtRunsAgainst.Text           = team.RunsAgainst.ToString();
                txtExpectedWinPercentage.Text = team.ExpectedWinningPercentage.ToString();
                txtRelativePowerIndex.Text    = team.RelativePowerIndex.ToString();
            }
        }
        protected void GetTeam()
        {
            //look up selected team and fill data in the form
            using (DefaultConnection db = new DefaultConnection())
            {
                Int32 TeamID = Convert.ToInt32(Request.QueryString["TeamID"]);

                //look up team
                Team team = (from t in db.Teams where t.TeamID == TeamID select t).FirstOrDefault();

                //fill data to form
                txtTeam.Text = team.TeamName;
                txtWins.Text = team.Wins.ToString();
                txtLosses.Text = team.Losses.ToString();
                txtRunsScored.Text = team.RunsScored.ToString();
                txtRunsAgainst.Text = team.RunsAgainst.ToString();
                txtExpectedWinPercentage.Text = team.ExpectedWinningPercentage.ToString();
                txtRelativePowerIndex.Text = team.RelativePowerIndex.ToString();

            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (DefaultConnection db = new DefaultConnection())
            {
                //create new team
                Team team = new Team();

                //check for url
                if(!String.IsNullOrEmpty(Request.QueryString["TeamID"]))
                {
                    Int32 TeamID = Convert.ToInt32(Request.QueryString["TeamID"]);

                    //look up team
                    team = (from t in db.Teams where t.TeamID == TeamID select t).FirstOrDefault();
                }

                    //fill properties of new team
                    team.TeamName = txtTeam.Text;
                    team.Wins = Convert.ToInt32(txtWins.Text);
                    team.Losses = Convert.ToInt32(txtLosses.Text);
                    team.RunsScored = Convert.ToInt32(txtRunsScored.Text);
                    team.RunsAgainst = Convert.ToInt32(txtRunsAgainst.Text);
                    team.ExpectedWinningPercentage = Convert.ToDecimal(txtExpectedWinPercentage.Text);
                    team.RelativePowerIndex = Convert.ToDecimal(txtRelativePowerIndex.Text);

                    //add if we have no url id
                    if (String.IsNullOrEmpty(Request.QueryString["TeamID"]))
                    {
                        db.Teams.Add(team);
                    }

                    //save the new team
                    db.SaveChanges();

                    //redirect
                    Response.Redirect("standings.aspx");

            }
        }
Example #8
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                //create a new user
                User objU = new User();

                //fill properties
                objU.Name = txtName.Text;
                objU.Username = txtUsername.Text;

                //salt and hash plain text pw
                String password = txtPassword.Text;
                String salt = CreateSalt(8);
                String pass_and_salt = password + salt;

                // Create a new instance of the hash crypto service provider.
                HashAlgorithm hashAlg = new SHA256CryptoServiceProvider();

                // Convert the data to hash to an array of Bytes.
                byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(pass_and_salt);

                // Compute the Hash. This returns an array of Bytes.
                byte[] bytHash = hashAlg.ComputeHash(bytValue);

                // Optionally, represent the hash value as a base64-encoded string, 
                // For example, if you need to display the value or transmit it over a network.
                string base64 = Convert.ToBase64String(bytHash);

                objU.Password = base64;
                objU.Salt = salt;

                //save
                db.Users.Add(objU);
                db.SaveChanges();
            }
        }
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                //create a new user
                User objU = new User();

                //fill properties
                objU.Name = txtName.Text;
                objU.Username = txtUsername.Text;

                //salt and hash plain text pw
                String password = txtPassword.Text;
                String salt = CreateSalt(8);
                String pass_and_salt = password + salt;

                // Create a new instance of the hash crypto service provider.
                HashAlgorithm hashAlg = new SHA256CryptoServiceProvider();

                // Convert the data to hash to an array of Bytes.
                byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(pass_and_salt);

                // Compute the Hash. This returns an array of Bytes.
                byte[] bytHash = hashAlg.ComputeHash(bytValue);

                // Optionally, represent the hash value as a base64-encoded string,
                // For example, if you need to display the value or transmit it over a network.
                string base64 = Convert.ToBase64String(bytHash);

                objU.Password = base64;
                objU.Salt = salt;

                //save
                db.Users.Add(objU);
                db.SaveChanges();
            }
        }
Example #10
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (DefaultConnection db = new DefaultConnection())
            {
                //create new team
                Team team = new Team();

                //check for url
                if (!String.IsNullOrEmpty(Request.QueryString["TeamID"]))
                {
                    Int32 TeamID = Convert.ToInt32(Request.QueryString["TeamID"]);

                    //look up team
                    team = (from t in db.Teams where t.TeamID == TeamID select t).FirstOrDefault();
                }

                //fill properties of new team
                team.TeamName    = txtTeam.Text;
                team.Wins        = Convert.ToInt32(txtWins.Text);
                team.Losses      = Convert.ToInt32(txtLosses.Text);
                team.RunsScored  = Convert.ToInt32(txtRunsScored.Text);
                team.RunsAgainst = Convert.ToInt32(txtRunsAgainst.Text);
                team.ExpectedWinningPercentage = Convert.ToDecimal(txtExpectedWinPercentage.Text);
                team.RelativePowerIndex        = Convert.ToDecimal(txtRelativePowerIndex.Text);

                //add if we have no url id
                if (String.IsNullOrEmpty(Request.QueryString["TeamID"]))
                {
                    db.Teams.Add(team);
                }

                //save the new team
                db.SaveChanges();

                //redirect
                Response.Redirect("standings.aspx");
            }
        }