新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
将用户名,密码,用户类型存在数据库中,登陆时比较输入的值是否与数据库相同即可。
成都创新互联专注为客户提供全方位的互联网综合服务,包含不限于网站设计、网站制作、黄冈网络推广、成都小程序开发、黄冈网络营销、黄冈企业策划、黄冈品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;成都创新互联为所有大学生创业者提供黄冈建站搭建服务,24小时服务热线:18980820575,官方网址:www.cdcxhl.com
基础类库:
Imports Microsoft.VisualBasic
'执行Access语句的封装类。
Public Class AccessExecClass
Private conn As Data.OleDb.OleDbConnection
Private cmd As Data.OleDb.OleDbCommand
'创建类对象,并连接到数据库。
Sub New()
If openAccess Then
Else
msgbox("open Access Fail.")
End If
End Sub
'创建类对象,并连接到数据库。 '输入带目录名称的数据库文件名称:dbFileName,例如:“\DB数据库\企业数据库.aspx”
Sub New(ByVal dbFileName As String)
If OpenAccess(dbFileName) Then
Else
MsgBox("open Access Fail.")
End If
End Sub
Function OpenAccess() As Boolean
OpenAccess = False
'检验用户的帐号密码是否正确
Dim provider As String '= ConfigurationManager.ConnectionStrings("ConnectionString").ProviderName
provider = "Provider=Microsoft.Jet.OLEDB.4.0"
Dim database As String
database = "Data Source=" System.Web.HttpContext.Current.Server.MapPath("\数据库.aspx") ";Persist Security Info=true"
conn = New Data.OleDb.OleDbConnection(provider ";" database)
conn.Open()
OpenAccess = True
End Function
Function OpenAccess(ByVal dbFileName As String) As Boolean
OpenAccess = False
'检验用户的帐号密码是否正确
Dim provider As String '= ConfigurationManager.ConnectionStrings("ConnectionString").ProviderName
provider = "Provider=Microsoft.Jet.OLEDB.4.0"
Dim database As String
database = "Data Source=" System.Web.HttpContext.Current.Server.MapPath(dbFileName) ";Persist Security Info=true"
conn = New Data.OleDb.OleDbConnection(provider ";" database)
conn.Open()
OpenAccess = True
End Function
'关闭数据库。
Sub CloseAccess()
cmd = Nothing
conn.Close()
End Sub
'执行一条Access语句,执行成功就返回True。
Function ExecAccessString(ByVal AccessStr As String) As Boolean
cmd = New Data.OleDb.OleDbCommand(AccessStr, conn)
cmd.ExecuteNonQuery()
'Dim aa As Data.OleDb.OleDbDataReader = cmd.ExecuteReader
ExecAccessString = True
End Function
'返回读取到的数据,注意是用地址传递方式返回
Sub ExecAccessString(ByVal AccessStr As String, ByRef AccessReader As Data.OleDb.OleDbDataReader)
cmd = New Data.OleDb.OleDbCommand(AccessStr, conn)
cmd.ExecuteNonQuery()
AccessReader = cmd.ExecuteReader
End Sub
End Class
登陆代码:
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
Dim wl As New WebLog '用户登录记录开始,仅对购买了Log 功能的用户,才开放此功能,否则不会实际记录Log
Dim sql As String
Dim aDB As New AccessExecClass
Dim mypw As String
Label1.Visible = False
Label2.Visible = False
Label3.Visible = False
Label4.Visible = False
'没有输入时,不能进行登陆
If TextBox1.Text = "" Then
Label1.Visible = True
Return
End If
If TextBox2.Text = "" Then
Label2.Visible = True
Return
End If
If TextBox3.Text = "" Then
Label3.Visible = True
Return
End If
If TextBox3.Text = TextBox4.Text Then
Else
Label3.Visible = True
Return
End If
Dim iRnd As Integer = Rnd(10) * 100
TextBox3.Text = ""
TextBox4.Text = iRnd.ToString
'Dim iRnd As Integer = Rnd(10) * 100
'注意:此处需要加入防止注入分析,包含'的肯定是特别语句,讲拒绝.
If TextBox1.Text.IndexOf("'") 0 Or TextBox2.Text.IndexOf("'") 0 Then
TextBox1.Text = "不能输入非法字符,将强制清空"
TextBox2.Text = ""
Else
Dim pw As New MD5EnCode(13, 19) ' '2次加密
sql = "select 权限组号,ID , 密码 from 编辑人数据 where 编辑姓名='" + TextBox1.Text + "'"
Dim aa As Data.OleDb.OleDbDataReader '= cmd.ExecuteReader
aDB.ExecAccessString(sql, aa)
If aa.Read() Then
'密码正确()
'sql = aa(2)'需要特别注意:只能单向解密,不能直接转换
mypw = pw.simDeCode(pw.simDeCode(aa(2)))
If TextBox2.Text = mypw Then
Session("LOGIN_Name") = TextBox1.Text '设置登录后的用户名称
Session("Login_Group") = aa(0) 'cmd.ExecuteScalar '设置登录后的权限级别
Session("Login_ID") = aa(1) 'cmd.ToString
'cmd = Nothing
'conn.Close()
Call wl.NewLog("登录", "管理员成功登录")
Response.Redirect("../WebManages/Default.ASPX")
Else
'密码错误()
sql = sql.Replace("'", "【单引号】")
sql = sql.Replace(",", "【逗号】")
Call wl.NewLog("登录", "管理员失败的登录", TextBox1.Text, sql.Replace("""", "【双引号】"), "")
Label4.Visible = True
End If
Else
'密码错误()
sql = sql.Replace("'", "【单引号】")
sql = sql.Replace(",", "【逗号】")
Call wl.NewLog("登录", "管理员失败的登录", TextBox1.Text, sql.Replace("""", "【双引号】"), "")
Label4.Visible = True
End If
End If
End Sub
Private Sub BtOk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btok.Click
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Admin.accdb;Persist Security Info=True")
Dim com As OleDbCommand = New OleDbCommand("select * from 用户名", con)
con.Open()
Dim h1 As OleDbDataReader
Dim table As New DataTable
h1 = com.ExecuteReader()
table.Load(h1)
If txtName.Text = "" Then
MsgBox("请输入用户名", MsgBoxStyle.OkCancel + MsgBoxStyle.Exclamation, "错误提示")
ElseIf txtName.Text "" And txtPasswd.Text = "" Then
MsgBox("请输入密码", MsgBoxStyle.OkCancel + MsgBoxStyle.Exclamation, "错误提示")
ElseIf table.Select("用户名='" txtName.Text "'").Length 0 Then
If table.Select("用户名='" txtName.Text "'")(0)("密码").ToString = txtPasswd.Text Then
MsgBox("成功登陆", MsgBoxStyle.OkCancel + MsgBoxStyle.Exclamation, "错误提示") Then
Form1.Show()
Me.Visible = False
Exit Sub
Else
MsgBox("密码错误", MsgBoxStyle.OkCancel + MsgBoxStyle.Exclamation, "错误提示")
End If
Else
MsgBox("用户名不存在", MsgBoxStyle.OkCancel + MsgBoxStyle.Exclamation, "错误提示")
Exit Sub
End If
table.Clear()
h1.Close()
con.Close()
End Sub
哈哈简单哪
第一步:登陆网页代码
第二步:登陆以后判断是否登陆成功
有两种方法:1.获取网页代码,判断网页字符有无”登陆成功”字样
源代码:
2.就是判断网页是否跳转到了某一页
源代码:
两种方法结合起来用,可以判断网页是否无法连接