<
%@ Page
Language
="vb" aspcompat=true
Codebehind
="WebForm7.aspx.vb"
Inherits
="jxacer.WebForm7"%
>
< %@ Import Namespace ="System.Data" % >
< %@ Import Namespace ="System.Data.OleDb" % >
< %@ Import Namespace=System.Diagnostics % >
< %@ Import Namespace=System.Security.Cryptography % >
< %@ Import Namespace=System.Text % >
< %@ Import Namespace=System.IO % >
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
< HTML >
< HEAD >
< title >WebForm7 </title>
< meta name ="GENERATOR" content ="Microsoft Visual Studio .NET 7.1" >
< meta name ="CODE_LANGUAGE" content ="Visual Basic .NET 7.1" >
< meta name ="vs_defaultClientScript" content ="JavaScript" >
< meta name ="vs_targetSchema" content ="http://schemas.microsoft.com/intellisense/ie5" >
</HEAD>
< body MS_POSITIONING ="GridLayout" >
< form id ="Form1" method ="post" runat ="server" >
< %if session("username")="" then% >
< table align ="center" >
< tr >
< td >用户名: </td>
< td > < asp:TextBox id ="TextBox1" runat ="server" > </asp:TextBox>
</td>
</tr>
< tr >
< td >密 码: </td>
< td > < asp:TextBox id ="TextBox2" runat ="server" > </asp:TextBox> </td>
</tr>
< tr >
< td >
验证码: </td>
< td > < asp:TextBox id ="TextBox3" runat ="server" > </asp:TextBox> </td>
</tr>
< tr >
< td colspan ="2" align ="center" > < asp:Image id ="Image1" runat ="server" ImageUrl ="VerifyChar.aspx" > </asp:Image> </td>
</tr>
< tr >
< td >
cookie: </td>
< td >
< asp:DropDownList id ="DropDownList1" runat ="server" Width ="152px" >
< asp:ListItem Value ="0" >不保存 </asp:ListItem>
< asp:ListItem Value ="30" >保存一个月 </asp:ListItem>
< asp:ListItem Value ="365" >保存一年 </asp:ListItem>
< asp:ListItem Value ="36500" >永久保存 </asp:ListItem>
</asp:DropDownList> </td>
</tr>
< tr >
< td colspan ="2" align ="center" >
< asp:Button id ="Button1" runat ="server" Text ="Button" > </asp:Button> </td>
</tr>
< tr >
< td colspan ="2" align ="center" > < %=Application("online")% > </td>
</tr>
</table>
< % else% >
< table align ="center" >
< tr >
< td > < %=session("username")% > </td> < td >
< asp:Button id ="Button2" runat ="server" Text ="Button" OnClick ="zhuxiao" > </asp:Button> </td>
</tr>
</table>
< %end if% >
</form>
< script language ="vb" runat ="server" >
Dim sql as String
Dim myconn as OleDbConnection
Dim myCmd as OleDbCommand
Dim conn, rs
'DES加密cookie
Private Shared KEY_64() As Byte = {42, 16, 93, 156, 78, 4, 218, 32}
Private Shared IV_64() As Byte = {55, 103, 246, 79, 36, 99, 167, 3}
Sub Page_Load(sender As Object, e As EventArgs)
If Not Request.Cookies("userInfo") Is Nothing Then
session("username") = Decrypt(Server.HtmlEncode(Request.Cookies( Decrypt("userInfo"))( Decrypt("userName"))))'解密字段,变量名,数据
End If
Dim strConn,username As String
strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&server.MapPath("/data/data.mdb")
myConn = New OledbConnection(strConn)
end sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If UCase(TextBox3.Text) = Session("VerifyChar") Then
conn = Server.CreateObject("adodb.connection")
conn.open("provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("data/data.mdb"))
sql = "select *from users where username='" & textbox1.text & "' and " & "mima='" & textbox2.text & "'"
rs = conn.execute(sql)
If Not rs.eof Then
Session("username") = textbox1.text
Session("bolauthenticated") = True
Response.Cookies(Encrypt("userInfo"))(Encrypt("userName")) =Encrypt(TextBox1.Text) '加密字段,变量名,数据
Response.Cookies(Encrypt("userInfo")).Expires = DateTime.Now.AddDays(DropDownList1.SelectedValue)
Else
Response.Write(" < script for=window event=onload >window.alert('用户名或密码错误!');Form1.TextBox1.foucs(); </" & "script>")
End If
else
Response.Write(" < script for=window event=onload >window.alert('验证码错误!');Form1.TextBox3.foucs(); </" & "script>")
End If
End Sub
sub zhuxiao(sender As Object, e As EventArgs)
Response.Cookies(Encrypt("userInfo")).Expires = DateTime.Now.AddDays(-1)
Session.Clear()
Session.Abandon()
end sub
'加密
public Shared Function Encrypt(ByVal value As String) As String
If value < > "" Then
Dim cryptoProvider As DESCryptoServiceProvider =New DESCryptoServiceProvider()
Dim ms As MemoryStream = New MemoryStream()
Dim cs As CryptoStream = New CryptoStream(ms, cryptoProvider.CreateEncryptor(KEY_64, IV_64),CryptoStreamMode.Write)
Dim sw As StreamWriter = New StreamWriter(cs)
sw.Write(value)
sw.Flush()
cs.FlushFinalBlock()
ms.Flush()
'再转换为一个字符串
Return Convert.ToBase64String(ms.GetBuffer(), 0, ms.Length)
End If
End Function
'解密
Public Shared Function Decrypt(ByVal value As String) As String
If value < > "" Then
Dim cryptoProvider As DESCryptoServiceProvider =New DESCryptoServiceProvider()
'从字符串转换为字节组
Dim buffer As Byte() = Convert.FromBase64String(value)
Dim ms As MemoryStream = New MemoryStream(buffer)
Dim cs As CryptoStream = New CryptoStream(ms, cryptoProvider.CreateDecryptor(KEY_64, IV_64), CryptoStreamMode.Read)
Dim sr As StreamReader = New StreamReader(cs)
Return sr.ReadToEnd()
End If
End Function
</script>
</body>
</HTML>
< %@ Import Namespace ="System.Data" % >
< %@ Import Namespace ="System.Data.OleDb" % >
< %@ Import Namespace=System.Diagnostics % >
< %@ Import Namespace=System.Security.Cryptography % >
< %@ Import Namespace=System.Text % >
< %@ Import Namespace=System.IO % >
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
< HTML >
< HEAD >
< title >WebForm7 </title>
< meta name ="GENERATOR" content ="Microsoft Visual Studio .NET 7.1" >
< meta name ="CODE_LANGUAGE" content ="Visual Basic .NET 7.1" >
< meta name ="vs_defaultClientScript" content ="JavaScript" >
< meta name ="vs_targetSchema" content ="http://schemas.microsoft.com/intellisense/ie5" >
</HEAD>
< body MS_POSITIONING ="GridLayout" >
< form id ="Form1" method ="post" runat ="server" >
< %if session("username")="" then% >
< table align ="center" >
< tr >
< td >用户名: </td>
< td > < asp:TextBox id ="TextBox1" runat ="server" > </asp:TextBox>
</td>
</tr>
< tr >
< td >密 码: </td>
< td > < asp:TextBox id ="TextBox2" runat ="server" > </asp:TextBox> </td>
</tr>
< tr >
< td >
验证码: </td>
< td > < asp:TextBox id ="TextBox3" runat ="server" > </asp:TextBox> </td>
</tr>
< tr >
< td colspan ="2" align ="center" > < asp:Image id ="Image1" runat ="server" ImageUrl ="VerifyChar.aspx" > </asp:Image> </td>
</tr>
< tr >
< td >
cookie: </td>
< td >
< asp:DropDownList id ="DropDownList1" runat ="server" Width ="152px" >
< asp:ListItem Value ="0" >不保存 </asp:ListItem>
< asp:ListItem Value ="30" >保存一个月 </asp:ListItem>
< asp:ListItem Value ="365" >保存一年 </asp:ListItem>
< asp:ListItem Value ="36500" >永久保存 </asp:ListItem>
</asp:DropDownList> </td>
</tr>
< tr >
< td colspan ="2" align ="center" >
< asp:Button id ="Button1" runat ="server" Text ="Button" > </asp:Button> </td>
</tr>
< tr >
< td colspan ="2" align ="center" > < %=Application("online")% > </td>
</tr>
</table>
< % else% >
< table align ="center" >
< tr >
< td > < %=session("username")% > </td> < td >
< asp:Button id ="Button2" runat ="server" Text ="Button" OnClick ="zhuxiao" > </asp:Button> </td>
</tr>
</table>
< %end if% >
</form>
< script language ="vb" runat ="server" >
Dim sql as String
Dim myconn as OleDbConnection
Dim myCmd as OleDbCommand
Dim conn, rs
'DES加密cookie
Private Shared KEY_64() As Byte = {42, 16, 93, 156, 78, 4, 218, 32}
Private Shared IV_64() As Byte = {55, 103, 246, 79, 36, 99, 167, 3}
Sub Page_Load(sender As Object, e As EventArgs)
If Not Request.Cookies("userInfo") Is Nothing Then
session("username") = Decrypt(Server.HtmlEncode(Request.Cookies( Decrypt("userInfo"))( Decrypt("userName"))))'解密字段,变量名,数据
End If
Dim strConn,username As String
strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&server.MapPath("/data/data.mdb")
myConn = New OledbConnection(strConn)
end sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If UCase(TextBox3.Text) = Session("VerifyChar") Then
conn = Server.CreateObject("adodb.connection")
conn.open("provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("data/data.mdb"))
sql = "select *from users where username='" & textbox1.text & "' and " & "mima='" & textbox2.text & "'"
rs = conn.execute(sql)
If Not rs.eof Then
Session("username") = textbox1.text
Session("bolauthenticated") = True
Response.Cookies(Encrypt("userInfo"))(Encrypt("userName")) =Encrypt(TextBox1.Text) '加密字段,变量名,数据
Response.Cookies(Encrypt("userInfo")).Expires = DateTime.Now.AddDays(DropDownList1.SelectedValue)
Else
Response.Write(" < script for=window event=onload >window.alert('用户名或密码错误!');Form1.TextBox1.foucs(); </" & "script>")
End If
else
Response.Write(" < script for=window event=onload >window.alert('验证码错误!');Form1.TextBox3.foucs(); </" & "script>")
End If
End Sub
sub zhuxiao(sender As Object, e As EventArgs)
Response.Cookies(Encrypt("userInfo")).Expires = DateTime.Now.AddDays(-1)
Session.Clear()
Session.Abandon()
end sub
'加密
public Shared Function Encrypt(ByVal value As String) As String
If value < > "" Then
Dim cryptoProvider As DESCryptoServiceProvider =New DESCryptoServiceProvider()
Dim ms As MemoryStream = New MemoryStream()
Dim cs As CryptoStream = New CryptoStream(ms, cryptoProvider.CreateEncryptor(KEY_64, IV_64),CryptoStreamMode.Write)
Dim sw As StreamWriter = New StreamWriter(cs)
sw.Write(value)
sw.Flush()
cs.FlushFinalBlock()
ms.Flush()
'再转换为一个字符串
Return Convert.ToBase64String(ms.GetBuffer(), 0, ms.Length)
End If
End Function
'解密
Public Shared Function Decrypt(ByVal value As String) As String
If value < > "" Then
Dim cryptoProvider As DESCryptoServiceProvider =New DESCryptoServiceProvider()
'从字符串转换为字节组
Dim buffer As Byte() = Convert.FromBase64String(value)
Dim ms As MemoryStream = New MemoryStream(buffer)
Dim cs As CryptoStream = New CryptoStream(ms, cryptoProvider.CreateDecryptor(KEY_64, IV_64), CryptoStreamMode.Read)
Dim sr As StreamReader = New StreamReader(cs)
Return sr.ReadToEnd()
End If
End Function
</script>
</body>
</HTML>