⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 default.aspx.cs

📁 这是asp.net^和Visual C++Sharp编写的串并口通讯的书籍 源代码
💻 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_user where MemberName='" + 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 = Decrypting(dr[3].ToString());//调解密方法解密
                    txtQuePwd.Text = dr[4].ToString();
                    txtAnsPwd.Text = Decrypting(dr[5].ToString());//调解密方法解密
                    txtEmail.Text = Decrypting(dr[6].ToString());//调解密方法解密

                }
                else
                {

                    Response.Write("<script>alert('没有找到任何记录!');</script>");
                }
            dr.Close();
            sqlconn.Close();
          

    }
    

    //加密字符串
    public string Encrypting(string strSource)
    {
        //把字符串放到byte数组中
        byte[] bytIn = System.Text.Encoding.Default.GetBytes(strSource);
        //建立加密对象的密钥和偏移量
        //使得输入密码必须输入英文文本
        byte[] iv = { 102, 16, 93, 156, 78, 4, 218, 32 };//定义偏移量
        byte[] key = { 55, 103, 246, 79, 36, 99, 167, 3 };//定义密钥
        //实例DES加密类
        DESCryptoServiceProvider mobjCryptoService = new DESCryptoServiceProvider();
        mobjCryptoService.Key = iv;
        mobjCryptoService.IV = key;
        ICryptoTransform encrypto = mobjCryptoService.CreateEncryptor();
        //实例MemoryStream流加密密文件
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Write);
        cs.Write(bytIn, 0, bytIn.Length);
        cs.FlushFinalBlock();
        return System.Convert.ToBase64String(ms.ToArray());
    }
    //解密字符串
    public string Decrypting(string Source)
    {

        //将解密字符串转换成字节数组
        byte[] bytIn = System.Convert.FromBase64String(Source);
        //给出解密的密钥和偏移量,密钥和偏移量必须与加密时的密钥和偏移量相同
        byte[] iv = { 102, 16, 93, 156, 78, 4, 218, 32 };//定义偏移量
        byte[] key = { 55, 103, 246, 79, 36, 99, 167, 3 };//定义密钥
        DESCryptoServiceProvider mobjCryptoService = new DESCryptoServiceProvider();
        mobjCryptoService.Key = iv;
        mobjCryptoService.IV = key;
        //实例流进行解密
        System.IO.MemoryStream ms = new System.IO.MemoryStream(bytIn, 0, bytIn.Length);
        ICryptoTransform encrypto = mobjCryptoService.CreateDecryptor();
        CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Read);
        StreamReader strd = new StreamReader(cs, Encoding.Default);
        return strd.ReadToEnd();
    }

    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 + -