referesh and encrypt

This commit is contained in:
EggMan20339 2024-03-26 20:22:41 -04:00
parent 48dff87b84
commit c0a46744b3
3 changed files with 162 additions and 20 deletions

View File

@ -14,30 +14,32 @@ namespace CH78
string studentID = "";
string gender;
string id = StudentDataTier.DecryptQueryString(Request.QueryString["ID"], "CNSAcnsa1", "salty");
if (!IsPostBack)
{
pageType = Request.QueryString["type"].Trim().ToUpper();
// retrieve the querystring
if (String.IsNullOrEmpty(Request.QueryString["ID"]))
if (String.IsNullOrEmpty(id))
{
// not the right entry point
Response.Redirect("Home.aspx");
}
else if (Request.QueryString["ID"].Trim().ToUpper() == "NEW")
else if (id.ToUpper() == "NEW")
{
BindDDL();
}
else if (Request.QueryString["type"].Trim().ToUpper() == "VIEW") // display
{
GetStudent(Request.QueryString["ID"].Trim(), Request.QueryString["type"].Trim().ToUpper());
GetStudent(id, Request.QueryString["type"].Trim().ToUpper());
}
else if (Request.QueryString["type"].Trim().ToUpper() == "EDIT") // edit
{
GetStudent(Request.QueryString["ID"].Trim(), Request.QueryString["type"].Trim().ToUpper());
GetStudent(id, Request.QueryString["type"].Trim().ToUpper());
}
else // anything else
@ -138,7 +140,21 @@ namespace CH78
protected void btnCancelStu_OnClick(object sender, EventArgs e)
{
System.Text.StringBuilder cb = new System.Text.StringBuilder();
cb.Append(" opener.location.href = 'home.aspx';");
cb.Append("var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;");
cb.Append(" if (ie7)");
cb.Append(" { ");
cb.Append("window.open('','_parent','');");
cb.Append("window.close();");
cb.Append(" }");
cb.Append(" else ");
cb.Append(" { ");
cb.Append(" this.focus();");
cb.Append(" self.opener = this;");
cb.Append(" self.close();");
cb.Append(" }");
ClientScript.RegisterClientScriptBlock(this.GetType(), "CloseReloadScript", cb.ToString(), true);
}
protected void btnGoStu_OnClick(object sender, EventArgs e)
@ -148,36 +164,97 @@ namespace CH78
{
}
else if (Request.QueryString["type"].Trim().ToUpper() == "EDIT")
{ StudentDataTier.UpdateStudents(0,
{
Decimal acct_bal = 0;
try
{
acct_bal = decimal.Parse(txtActBal.Text);
}
catch (Exception exception)
{
}
Decimal creds = 0;
try
{
creds = decimal.Parse(txtCreds.Text);
}
catch (Exception exception)
{
}
DateTime date = new DateTime(3000, 1, 1);
try
{
date = DateTime.Parse(txtDOB.Text);
}
catch (Exception exception)
{
}
StudentDataTier.UpdateStudents(0,
txtStuID.Text,
txtFNAME.Text,
txtLNAME.Text,
txtMidInit.Text,
DateTime.Parse(txtDOB.Text),
date,
txtGender.Text,
decimal.Parse(txtActBal.Text),
acct_bal,
txtMajor.Text, txtCellPhone.Text,
txtAdr1.Text,
txtCity.Text,
txtState.ToString(),
txtZip.Text,
decimal.Parse(txtCreds.Text));
creds);
}
else if (Request.QueryString["type"].Trim().ToUpper() == "NEW")
{ StudentDataTier.UpdateStudents(1,
{
Decimal acct_bal = 0;
try
{
acct_bal = decimal.Parse(txtActBal.Text);
}
catch (Exception exception)
{
}
Decimal creds = 0;
try
{
creds = decimal.Parse(txtCreds.Text);
}
catch (Exception exception)
{
}
DateTime date = new DateTime(3000, 1, 1);
try
{
date = DateTime.Parse(txtDOB.Text);
}
catch (Exception exception)
{
}
StudentDataTier.UpdateStudents(1,
txtStuID.Text,
txtFNAME.Text,
txtLNAME.Text,
txtMidInit.Text,
DateTime.Parse(txtDOB.Text),
date,
txtGender.Text.ToString(),
decimal.Parse(txtActBal.Text),
acct_bal,
txtMajor.Text, txtCellPhone.Text,
txtAdr1.Text,
txtCity.Text,
txtState.Text.ToString(),
txtZip.Text,
decimal.Parse(txtCreds.Text));
creds);
}

View File

@ -20,6 +20,15 @@ namespace CH78
if (!IsPostBack)
{
Cache.Remove("StudentData");
BindData();
}
else
{
if (Convert.ToString(Session["GRIDREFRESH"]) != "")
{
BindData();
}
}
@ -236,10 +245,12 @@ namespace CH78
// Get the record
recordToBeEdited = (e.CommandArgument.ToString().Trim());
recordToBeEdited = StudentDataTier.EncryptQueryString(recordToBeEdited, "CNSAcnsa1", "salty");
// this script will open a popup
sb.Append("<script language='javascript'>");
sb.Append("window.open('Display.aspx?ID=" + recordToBeEdited.ToString() + "&type=Edit" +"' , 'DisplayEdit',");
sb.Append("'width=1525, height=525, menubar=no, resizable=yes, left=50, top=50, scrollbars=yes');");
sb.Append("'width=1025, height=525, menubar=no, resizable=yes, left=50, top=50, scrollbars=yes');");
sb.Append("</script>");
// register with ClientScript
@ -267,7 +278,7 @@ namespace CH78
// this script will open a popup
sb.Append("<script language='javascript'>");
sb.Append("window.open('Display.aspx?ID=NEW&type=NEW' , 'DisplayEdit',");
sb.Append("'width=1525, height=525, menubar=no, resizable=yes, left=50, top=50, scrollbars=yes');");
sb.Append("'width=1025, height=525, menubar=no, resizable=yes, left=50, top=50, scrollbars=yes');");
sb.Append("</script>");
// register with ClientScript

View File

@ -3,6 +3,11 @@ using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.UI.WebControls;
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Web;
namespace CH78
{
@ -24,6 +29,55 @@ namespace CH78
}
public static string EncryptQueryString(string inputText, string key, string salt)
{
byte[] plainText = Encoding.UTF8.GetBytes(inputText);
using (RijndaelManaged rijndaelCipher = new RijndaelManaged())
{
PasswordDeriveBytes secretKey = new PasswordDeriveBytes(Encoding.ASCII.GetBytes(key), Encoding.ASCII.GetBytes(salt));
using (ICryptoTransform encryptor = rijndaelCipher.CreateEncryptor(secretKey.GetBytes(32), secretKey.GetBytes(16)))
{
using (MemoryStream memoryStream = new MemoryStream())
{
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
{
cryptoStream.Write(plainText, 0, plainText.Length);
cryptoStream.FlushFinalBlock();
string base64 = Convert.ToBase64String(memoryStream.ToArray());
// Generate a string that won't get screwed up when passed as a query string.
string urlEncoded = HttpUtility.UrlEncode(base64);
return urlEncoded;
}
}
}
}
}
public static string DecryptQueryString(string inputText, string key, string salt)
{
byte[] encryptedData = Convert.FromBase64String(inputText);
PasswordDeriveBytes secretKey = new PasswordDeriveBytes(Encoding.ASCII.GetBytes(key), Encoding.ASCII.GetBytes(salt));
using (RijndaelManaged rijndaelCipher = new RijndaelManaged())
{
using (ICryptoTransform decryptor = rijndaelCipher.CreateDecryptor(secretKey.GetBytes(32), secretKey.GetBytes(16)))
{
using (MemoryStream memoryStream = new MemoryStream(encryptedData))
{
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
{
byte[] plainText = new byte[encryptedData.Length];
cryptoStream.Read(plainText, 0, plainText.Length);
string utf8 = Encoding.UTF8.GetString(plainText);
return utf8;
}
}
}
}
}
public DataSet GetStudents()
{