public void btnSaveLogin_Click(object sender, EventArgs e) { try { DungeonTrackerDataContext dtdc = new DungeonTrackerDataContext(); string passwordToCompare = hashPasswordToCompare(); DD_User user = dtdc.DD_Users.SingleOrDefault(u => u.Username.ToLower() == txtUsername.Text.ToLower() && u.Password == passwordToCompare); if (user != null) { LoginHelper.setupSessionVariables(user); EventHelper.TriggerEvent(save, this, user); } else { //displayError(); } //EventHelper.TriggerEvent(save, this, null); } catch (Exception ex) { //displayError(ex); showModal(); } }
static public void setupSessionVariables(DD_User user) { DungeonTrackerDataContext dtdc = new DungeonTrackerDataContext(); HttpSessionState Session = HttpContext.Current.Session; Session["UserID"] = user.ID; Session["Username"] = user.Username; }
protected void LoadUserInformation() { DungeonTrackerDataContext dtdc = new DungeonTrackerDataContext(); DD_User user = dtdc.DD_Users.Single(u => u.ID == Convert.ToInt32(Session["UserID"])); lblName.Text = "Name: " + user.FirstName + " " + user.LastName; lblEmail.Text = "Email: " + user.Email; }
protected void btnSaveAddUser_Click(object sender, EventArgs e) { try { DungeonTrackerDataContext dtdc = new DungeonTrackerDataContext(); DD_User addUser = new DD_User(); SHA256 shaPassword = SHA256.Create(); Byte[] password = ASCIIEncoding.Default.GetBytes(txtPassword.Text); Byte[] hash = shaPassword.ComputeHash(password); addUser.LastName = txtLastName.Text.ToLower(); addUser.FirstName = txtFirstName.Text.ToLower(); addUser.Password = BitConverter.ToString(hash); addUser.DateCreated = DateTime.Today; if (!dtdc.DD_Users.Any(s => s.Username == txtUsername.Text.ToLower())) { addUser.Username = txtUsername.Text.ToLower(); if (!dtdc.DD_Users.Any(s => s.Email == txtEmail.Text.ToLower())) { addUser.Email = txtEmail.Text; //Inserts the new user to the database on a database submit. dtdc.DD_Users.InsertOnSubmit(addUser); dtdc.SubmitChanges(); } else { //That Email has already been used. } } else { //That username has already been used. } } catch (Exception ex) { } }