📄 default.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Security.Cryptography;
using System.Text;
using System.Data.SqlClient;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
//检测用户名是否存在
public void CheckUser()
{
SqlConnection sqlconn = new SqlConnection("server=(local);uid=sa;pwd=;database=db_08");
string sqlstr = "select * from tb_04 where Name='" + this.txtLoginName.Text + "'";
sqlconn.Open();
SqlCommand sqlcom = new SqlCommand(sqlstr, sqlconn);
SqlDataReader dr = sqlcom.ExecuteReader();
if (dr.Read())
{
if (dr[2].ToString() == "男")
{
ddlSex.SelectedIndex = 0;
}
if (dr[2].ToString() == "女")
{
ddlSex.SelectedIndex = 1;
}
txtPwd.Text = RSADecrypt(dr[3].ToString());//调解密方法解密
txtQuePwd.Text = dr[4].ToString();
txtAnsPwd.Text = RSADecrypt(dr[5].ToString());//调解密方法解密
txtEmail.Text = RSADecrypt(dr[6].ToString());//调解密方法解密
}
else
{
Response.Write("<script>alert('没有找到任何记录!');</script>");
}
dr.Close();
sqlconn.Close();
}
//解密字符串
public string RSADecrypt(string m_strDecryptString)
{
try
{
byte[] PlainTextBArray;
byte[] DypherTextBArray;
string Result;
System.Security.Cryptography.RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
//将公有密钥从publickey.txt中读出来加密字符串
String path = Server.MapPath("key");//保存密钥文件夹
//将私有密钥保存在文件
StreamReader redKey = new StreamReader(path + "/privatekey.txt", UTF8Encoding.UTF8, true);
rsa.FromXmlString(redKey.ReadToEnd());//初始化密钥
redKey.Close(); ;
//将解密字符串转化成字符节数组
PlainTextBArray = Convert.FromBase64String(m_strDecryptString);
//调用Decrypt()方法解字符串
DypherTextBArray = rsa.Decrypt(PlainTextBArray, false);
Result = (new UnicodeEncoding()).GetString(DypherTextBArray);
return Result;
}
catch (Exception ex)
{
throw new Exception("在解密的时候出现错误!错误提示: \n" + ex.Message);
}
}
protected void Button2_Click(object sender, EventArgs e)
{
CheckUser();
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script>window.close();</script>");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -