Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Init(ByVal sender As


Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        If Request.Cookies("username") IsNot Nothing And Request.Cookies("userpass") IsNot Nothing Then
            Dim username As String = HttpUtility.UrlDecode(Request.Cookies("username").Value.Trim().ToLower())
            Dim userpass As String = HttpUtility.UrlDecode(Request.Cookies("userpass").Value.Trim().ToLower())
            'Using sds As SqlDataSource = New SqlDataSource("Data Source=.;Initial Catalog=master;User ID=sa;Password=Abcdefg1", "select count(*) from t_user where username = @username and userpass = @userpass")
            'Using sds As SqlDataSource = New SqlDataSource(Dao.cs, "select count(*) from t_user where username = @username and userpass = @userpass")
            Using sds As SqlDataSource = New SqlDataSource(ConfigurationManager.ConnectionStrings("mydata").ConnectionString, "select count(*) from t_user where username = @username and userpass = @userpass")
                sds.SelectParameters.Add("username", username)
                sds.SelectParameters.Add("userpass", userpass)
                Dim ie As IEnumerable = sds.Select(DataSourceSelectArguments.Empty)
                Dim dv As System.Data.DataView = ie
                Dim i As Integer = dv(0)(0)
                If i > 0 Then
                    Response.Redirect("~/Index.aspx")
                End If
            End Using
        End If
    End Sub

    Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
        Dim username As String = Me.Login1.UserName.Trim().ToLower()
        Dim userpass As String = Me.Login1.Password.Trim().ToLower()
        Dim b As Boolean = Me.Login1.RememberMeSet
        'Using sds As SqlDataSource = New SqlDataSource("Data Source=.;Initial Catalog=master;User ID=sa;Password=Abcdefg1", "select count(*) from t_user where username = @username and userpass = @userpass")
        'Using sds As SqlDataSource = New SqlDataSource(Dao.cs, "select count(*) from t_user where username = @username and userpass = @userpass")
        Using sds As SqlDataSource = New SqlDataSource(ConfigurationManager.ConnectionStrings("mydata").ConnectionString, "select count(*) from t_user where username = @username and userpass = @userpass")
            sds.SelectParameters.Add("username", username)
            sds.SelectParameters.Add("userpass", userpass)
            Dim ie As IEnumerable = sds.Select(DataSourceSelectArguments.Empty)
            Dim dv As System.Data.DataView = ie
            Dim i As Integer = dv(0)(0)
            If i > 0 Then
                Response.Cookies("username").Value = HttpUtility.UrlEncode(username)
                Response.Cookies("userpass").Value = HttpUtility.UrlEncode(userpass)
                If b Then
                    Response.Cookies("username").Expires = DateTime.Now.AddDays(7) '设置cookie超时时间为7天
                    Response.Cookies("userpass").Expires = DateTime.Now.AddDays(7)
                End If
                Response.Redirect("~/Index.aspx") '登录成功跳转
            End If
        End Using
    End Sub
End Class

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
自己写的简单DES加密加密 public partial class _Default : System.Web.UI.Page { private static byte[] Key64 = { 42, 16, 93, 156, 78, 4, 218, 32 }; private static byte[] IV64 = { 55, 103, 246, 79, 36, 99, 167, 3 }; protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string p = Server.MapPath("~/wcn/"); int i; FileStream fin = new FileStream(p+TextBox1.Text, FileMode.Open, FileAccess.Read); FileStream fout = new FileStream(p+TextBox2.Text, FileMode.OpenOrCreate, FileAccess.Write); FileStream skey = new FileStream(p + "key.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite); FileStream siv = new FileStream(p + "key.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite); fout.SetLength(0); byte[] bin = new byte[100]; long rdlen = 0; long totlen = fin.Length; int len; DES des = new DESCryptoServiceProvider(); des.Key = Key64; des.IV = IV64; TextBox3.Text = des.Key[0].ToString(); StreamWriter w = new StreamWriter(skey); w.Write(des.Key[0]); w.Flush(); for (i = 0; i < 8; i++) { TextBox3.Text = TextBox3.Text + "," + des.Key[i].ToString(); //StreamWriter w = new StreamWriter(skey); w.Write(","+des.Key[i]); w.Flush(); } CryptoStream encStream = new CryptoStream(fout, des.CreateEncryptor(), CryptoStreamMode.Write); while (rdlen < totlen) { len = fin.Read(bin, 0, 100); encStream.Write(bin, 0, len); rdlen = rdlen + len; } encStream.Close(); fout.Close(); fin.Close(); } protected void Button3_Click(object sender, EventArgs e) { string p = Server.MapPath("~/wcn/"); FileStream fin = new FileStream(p + TextBox4.Text, FileMode.Open, FileAccess.Read); FileStream fout = new FileStream(p + TextBox5.Text, FileMode.OpenOrCreate, FileAccess.Write); fout.SetLength(0); byte[] bin = new byte[100]; long rdlen = 0; long totlen = fin.Length; int len; DES des = new DESCryptoServiceProvider(); des.Key = Key64; des.IV = IV64; CryptoStream decStream = new CryptoStream(fout, des.CreateDecryptor(), CryptoStreamMode.Write); while (rdlen < totlen) { len = fin.Read(bin, 0, 100); decStream.Write(bin, 0, len); rdlen = rdlen + len; } decStream.Close(); fout.Close(); fin.Close(); } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值