protected void btnLogin_Click(object sender, EventArgs e) { try { string email = txtEmail.Text.ToString(); string password = txtPassword.Text.ToString(); bool error = false; litError.Text = ""; Classes.Validation objValidate = new Classes.Validation(); if (!objValidate.isValidEmail(email)) { error = true; litError.Text += "Invalid Email Address<br>"; } if (!objValidate.isValidPassword(password)) { error = true; litError.Text += "Invalid Password<br>"; } if (error) return; Classes.Cryptography crypto = new Classes.Cryptography(); password = crypto.genPassHash(password); Classes.User objUser = new Classes.User(); if (password == objUser.getPassword(email)) { Session["username"] = email; Session["loggedIn"] = "true"; Session["role"] = objUser.getRole(email); Response.Redirect("Dashboard.aspx"); } else { litError.Text = "Invalid Account Login Information Provided"; } } catch (Exception ex) { litError.Text = "Invalid Account Login Information Provided"; } }
protected void btnUpdate_Click(object sender, EventArgs e) { Classes.User objUser = new Classes.User(); Classes.Cryptography objCrypto = new Classes.Cryptography(); Classes.Validation objValidate = new Classes.Validation(); try { string email = Session["username"].ToString(); string oldPassword = txtOldPassword.Text.ToString(); string newPassword = txtNewPassword.Text.ToString(); bool error = false; if (objUser.getPassword(email) != objCrypto.genPassHash(oldPassword)) { error = true; litError.Text += "Incorrect Old Password<br>"; } if (!objValidate.isValidPassword(newPassword)) { error = true; litError.Text = "Invalid New Password"; } if (newPassword != txtConfNewPassword.Text.ToString()) { error = true; litError.Text = "Passwords Do Not Match"; } if (error) return; if (objUser.setPassword(email, newPassword)) { litError.Text = "Password Updated Successfully"; } } catch (Exception ex) { litError.Text = "Password Could Not Be Updated"; } objUser.close(); }