Exemplo n.º 1
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                //create user object
                Users objU = new Users();

                //get salt for username
                String username = txtUsername.Text;

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

                //username was found
                if (objU != null){
                    String salt = objU.Salt;

                    //salt and hash text password
                    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 password is correct
                    if (objU.Password == base64)
                    {
                        //store id in session object
                        Session["UserID"] = objU.UserID;
                        Session["UserName"] = objU.Firstname + " " + objU.Lastname;

                        //redirect to their comic page
                        Response.Redirect("comics.aspx");
                    }
                    else
                    {
                        lblError.Text = "Invalid Login";
                    }
                }
                else
                {
                    lblError.Text = "Invalid Login";
                }
                }
        }
Exemplo n.º 2
0
 protected void GetAuthors()
 {
     using (DefaultConnection db = new DefaultConnection())
     {
         var track = from t in db.Comics1
                     select t;
         //bind to grid
         grdAuthors.DataSource = track.ToList();
         grdAuthors.DataBind();
     }
 }
Exemplo n.º 3
0
        protected void GetPublishers()
        {
            //get list of comics
            using (DefaultConnection db = new DefaultConnection())
            {
                var track = from t in db.Comics1
                            select t;

                //bind to the grid
                grdPublishers.DataSource = track.ToList();
                grdPublishers.DataBind();
            }
        }
Exemplo n.º 4
0
        protected void GetComics()
        {
            //list comics for user
            using (DefaultConnection db = new DefaultConnection())
            {
                var track = from t in db.Comics1
                            select t;

                //bind to grid
                grdComics.DataSource = track.ToList();
                grdComics.DataBind();
            }
        }
Exemplo n.º 5
0
        protected void GetComic()
        {
            //look up comic and fill
            using (DefaultConnection db = new DefaultConnection())
            {
                Int32 ComicID = Convert.ToInt32(Request.QueryString["ComicID"]);

                //look up comic
                Comics trac = (from c in db.Comics1
                               where c.ComicID == ComicID
                               select c).FirstOrDefault();

                txtTitle.Text = trac.Title;
                txtAuthor.Text = trac.Author;
                txtPublisher.Text = trac.Issue.ToString();
            }
        }
Exemplo n.º 6
0
        protected void grdComics_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //identify
            Int32 ComicID = Convert.ToInt32(grdComics.DataKeys[e.RowIndex].Values["ComicID"]);

            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                Comics track = (from c in db.Comics1
                                where c.ComicID == ComicID
                                select c).FirstOrDefault();

                //delete
                db.Comics1.Remove(track);
                db.SaveChanges();

                //refresh grid
                GetComics();
            }
        }
Exemplo n.º 7
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                Comics trac = new Comics();

                Int32 ComicID = 0;

                //check for url
                if (!String.IsNullOrEmpty(Request.QueryString["ComicID"]))
                {
                    //get id from url
                     ComicID = Convert.ToInt32(Request.QueryString["ComicID"]);

                    trac = (from c in db.Comics1
                            where c.ComicID == ComicID
                            select c).FirstOrDefault();
                }

                //fill properties
                trac.Title = txtTitle.Text;
                trac.Author = txtAuthor.Text;
                trac.Publisher = txtPublisher.Text;
                trac.Issue = Convert.ToInt32(txtIssue.Text);

                //no id in the url
                if (ComicID == 0)
                {
                    db.Comics1.Add(trac);
                }

                //save
                db.SaveChanges();

                //redirect
                Response.Redirect("tracker.aspx");
            }
        }
Exemplo n.º 8
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            //connect to db
            using (DefaultConnection db = new DefaultConnection())
            {
                //create new user
                Users objU = new Users();

                //fill the form inputs
                objU.Firstname = txtFirstname.Text;
                objU.Lastname = txtLastname.Text;
                objU.Username = txtUsername.Text;

                //salt and hash text password
                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.Users1.Add(objU);
                db.SaveChanges();
            }
        }