原创的用户登录服务器控件[vb.net]

服务器|控件|原创

自学.net一年,第一个自己写的用户登录控件
事件CheckedResult,该事件参数e继承自EventArgs,含有用户名,密码,登录合法性(布尔值)
事件EnterEmpty,当用户名、密码文体框为空值时引发
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data.SqlClient
")> Public Class Login
    Inherits System.Web.UI.WebControls.WebControl
    Implements IPostBackDataHandler
    Public Delegate Sub CheckedEvent(ByVal sender As Object, ByVal e As LoginEvent)
    Public Event EnterEmpty As EventHandler
    Public Event CheckedResult As CheckedEvent
    Private _user As String
    Private _pass As String
    Private _dataBase As String
    Private _dataTable As String
    Private _dataBaseUserName As String
    Private _dataBasePass As String
    Private _server As String
    Private _colUser As String
    Private _colPass As String
    Private _txtUser As String
    Private _txtPass As String
    Public Property ColUser() As String        属性--用户名字段
        Get
            Return _colUser
        End Get
        Set(ByVal value As String)
            _colUser = value
        End Set
    End Property
    Public Property ColPass() As String        属性--密码字段
        Get
            Return _colPass
        End Get
        Set(ByVal value As String)
            _colPass = value
        End Set
    End Property
    Public Property Server() As String        属性--SQL服务器名
        Get
            Return _server
        End Get
        Set(ByVal value As String)
            _server = value
        End Set
    End Property
    Public Property DataBaseUserName() As String        属性--数据库登录用户
        Get
            Return _dataBaseUserName
        End Get
        Set(ByVal value As String)
            _dataBaseUserName = value
        End Set
    End Property
    Public Property DataBasePass() As String        属性--数据库登录密码
        Get
            Return _dataBasePass
        End Get
        Set(ByVal value As String)
            _dataBasePass = value
        End Set
    End Property
    Public Property DataBase() As String        属性--数据库名
        Get
            Return _dataBase
        End Get
        Set(ByVal value As String)
            _dataBase = value
        End Set
    End Property
    Public Property DataTable() As String        属性--数据表
        Get
            Return _dataTable
        End Get
        Set(ByVal value As String)
            _dataTable = value
        End Set
    End Property
    Private ReadOnly Property ConnStr() As String        属性--构成连接字符串
        Get
            Dim _connStr As New Text.StringBuilder()
            With _connStr
                .Append("server=" & Server & ";")
                .Append("Initial catalog=" & DataBase & ";")
                .Append("User ID=" & DataBaseUserName & ";")
                .Append("PassWord=" & DataBasePass & ";")
            End With
            Return _connStr.ToString
        End Get
    End Property
    Private Property txtUser() As String        属性--获取用户名文本框值
        Get
            Return _txtUser
        End Get
        Set(ByVal value As String)
            _txtUser = value
        End Set
    End Property
    Private Property txtPass() As String        属性--获取密码文本框值
        Get
            Return _txtPass
        End Get
        Set(ByVal value As String)
            _txtPass = value
        End Set
    End Property
    Private Sub CheckInit()                     过程--验证连接数据库字符串的完整性
        If DataBase = "" Or DataTable = "" Or DataBaseUserName = "" Or DataBasePass = "" Then
            Throw New Exception("缺少相应的参数!")
        End If
    End Sub
    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter) 呈现服务器控件
 Try
            CheckInit()
            writer.RenderBeginTag(HtmlTextWriterTag.Table)
            writer.RenderBeginTag(HtmlTextWriterTag.Tr)
            writer.RenderBeginTag(HtmlTextWriterTag.Td)
            writer.Write("用户名:")
            writer.RenderEndTag()
            writer.RenderBeginTag(HtmlTextWriterTag.Td)
            writer.AddAttribute(HtmlTextWriterAttribute.Type, "TextBox")
            writer.AddAttribute(HtmlTextWriterAttribute.Name, Me.UniqueID & ":User")
            writer.AddAttribute(HtmlTextWriterAttribute.Maxlength, "30")
            writer.RenderBeginTag(HtmlTextWriterTag.Input)
            writer.RenderEndTag()
            writer.RenderEndTag()
            writer.RenderEndTag()
            writer.RenderBeginTag(HtmlTextWriterTag.Tr)
            writer.RenderBeginTag(HtmlTextWriterTag.Td)
            writer.Write("密码:")
            writer.RenderEndTag()
            writer.RenderBeginTag(HtmlTextWriterTag.Td)
            writer.AddAttribute(HtmlTextWriterAttribute.Type, "Password")
            writer.AddAttribute(HtmlTextWriterAttribute.Name, Me.UniqueID & ":Pass")
            writer.AddAttribute(HtmlTextWriterAttribute.Maxlength, "30")
            writer.RenderBeginTag(HtmlTextWriterTag.Input)
            writer.RenderEndTag()
            writer.RenderEndTag()
            writer.RenderEndTag()
            writer.RenderBeginTag(HtmlTextWriterTag.Tr)
            writer.AddAttribute(HtmlTextWriterAttribute.Cols, "2")
            writer.RenderBeginTag(HtmlTextWriterTag.Td)
            writer.AddAttribute(HtmlTextWriterAttribute.Type, "submit")
            writer.AddAttribute(HtmlTextWriterAttribute.Name, Me.UniqueID)
            writer.AddAttribute(HtmlTextWriterAttribute.value, "提交")
            writer.RenderBeginTag(HtmlTextWriterTag.Input)
            writer.RenderEndTag()
            writer.RenderEndTag()
; writer.RenderEndTag()
            writer.RenderEndTag()
        Catch _error As Exception
            System.Web.HttpContext.Current.Response.Write("未能完成请求,错误信息如下:" & _error.Message)
            Exit Sub
        End Try
    End Sub
    Public Function LoadPostData(ByVal postDataKey As String, ByVal postCollection As System.Collections.Specialized.NamevalueCollection) As Boolean Implements System.Web.UI.IPostBackDataHandler.LoadPostData
        Dim _txtUserName As String = postCollection(Me.UniqueID & ":User")
        Dim _txtPass As String = postCollection(Me.UniqueID & ":Pass")
        If _txtUserName = "" Or _txtPass = "" Then
            Return True
        Else
            txtUser = _txtUserName
            txtPass = _txtPass
            OnCheckMain()
            Return False
        End If
    End Function     Public Sub RaisePostDataChangedEvent() Implements System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent
        RaiseEvent EnterEmpty(Me, New EventArgs())
    End Sub
    Private Sub OnCheckMain()                            验证用户的合法性,引发CheckedResult事件
        Dim _connStr As String = ConnStr
        Dim _conn As New SqlConnection(_connStr)
        Dim _comm As New SqlCommand()
        Dim _dataReader As SqlDataReader
        Try
            _comm.Connection = _conn
            _comm.CommandText = "select * from " & DataTable & " where " & ColUser & "= " & txtUser & " and " & ColPass & "= " & txtPass & " "
            _comm.CommandType = CommandType.Text
            _conn.Open()
            _dataReader = _comm.ExecuteReader(CommandBehavior.CloseConnection)
            If _dataReader.Read Then
                RaiseEvent CheckedResult(Me, New LoginEvent(txtUser, txtPass, True))
            Else
                RaiseEvent CheckedResult(Me, New LoginEvent(txtUser, txtPass, False))
            End If
            _dataReader.Close()
        Catch _error As Exception
            Throw New Exception(_error.Message)
        Finally
            If _conn.State = ConnectionState.Open Then _conn.Close()
        End Try
    End Sub
End Class
---------------------------------------------------------源码2
2004.6.10
Programmer by czclk
自定义事件类LoginEvent,该事件参数e继承自EventArgs,含有用户名,密码,登录合法性(布尔值)
Public Class LoginEvent
    Inherits EventArgs
    Public Sub New()
    End Sub
    Public Sub New(ByVal user As String, ByVal pass As String, ByVal result As Boolean)
        _userName = user
        _userPass = pass
        _CheckedPass = result
    End Sub
    Private _userName As String
    Private _userPass As String
    Private _CheckedPass As Boolean
    Public Property CheckPass() As Boolean
        Get
            Return _CheckedPass
        End Get
        Set(ByVal value As Boolean)
            _CheckedPass = value
        End Set
    End Property
    Public Property UserName() As String
        Get
            Return _userName
        End Get
        Set(ByVal value As String)
            _userName = value
        End Set
    End Property
    Public Property UserPass() As String
        Get
            Return _userPass
        End Get
        Set(ByVal value As String)
            _userPass = value
        End Set
    End Property
End Class

时间: 2024-10-31 18:17:26

原创的用户登录服务器控件[vb.net]的相关文章

怎么防止非法用户登录我们的服务器呢

摘要: 怎么防止非法用户登录我们的服务器呢?这个问题困扰了太多人,网站被入侵,黑客的下一步就是提权.提权就是提升WEB后门的权限,拿到服务器的超级管理权限,从而控制整个服务器. 怎么防止非法用户登录我们的服务器呢?这个问题困扰了太多人,网站被入侵,黑客的下一步就是提权.提权就是提升WEB后门的权限,拿到服务器的超级管理权限,从而控制整个服务器.上次俺的小站就被入侵后,被人提权.新建了一个管理员帐号,不过我早已做了安全设置,防止非法用户登录,才没有造成进一步的损失.今天就这个问题,教大家一招防止非

巧妙设置防非法用户登录服务器

中介交易 http://www.aliyun.com/zixun/aggregation/6858.html">SEO诊断 淘宝客 云主机 技术大厅 怎么防止非法用户登录我们的服务器呢?这个问题困扰了太多人,网站被入侵,黑客的下一步就是提权.提权就是提升WEB后门的权限,拿到服务器的超级管理权限,从而控制整个服务器.上次俺的小站就被入侵后,被人提权.新建了一个管理员帐号,不过我早已做了安全设置,防止非法用户登录,才没有造成进一步的损失.今天就这个问题,教大家一招防止非法用户登录我们的服务器

菜鸟提问:用户登录窗口设计?

问题描述 我正在用VB.net制作一个简单的管理系统,谁能帮俺作一个用户登录窗口,谢谢!! 解决方案 解决方案二:在登陆里有,拉过来就好了解决方案三:不好意思!"在登陆里有,拉过来就好了"这是什么意思?我是要作一个窗口,从那拉??请您多多指导谢谢!!解决方案四:添加新项里面有个登录窗体解决方案五:自己做也很容易呀把几个控件(标签.文本框和命令按钮)加进来,加几行代码就能搞定,呵呵解决方案六:行,我试试,谢谢了!解决方案七:谢谢了,我试试看!!解决方案八:<%@PageLangua

Fedora10无法使用root用户登录的解决方案

本文为原创,如需转载,请注明作者和出处,谢谢!     最近测试fedora10,发现fedora竟然无法使用root用户进行登录,就算root的密码输入正确也不行.虽然大正常的工作中尽尽量避免使用root用户进行登录.但在其他情况,如学习.完成个人的工作等,以root用户登录还是很方便的(如果用其他用户登录会有很多限制).     最简单的解决方案是修改/etc/pam.d/gdm文件的内容.先以普通用户进行登录,然后打开/etc/pam.d/gdm文件,将如下一行使用#注释: auth re

拒绝平庸:浅谈用户登录页面的设计表现形式

用户活跃度是检验产品成功与否的重要指标之一,传统行业的商家极为重视门面的装潢,因为一个好的门面可以聚集人气,招揽更多的顾客.古时候的大户人家院子门口的石狮子或其他的摆件的摆放极为讲究,有一定的风水学说道理,更能彰显主人家的身份地位.由此可见,"门面'就如人的脸面之于人的形象一样重要,而WEB的登录页面就相当传统的"门面". 现在越来越多的大型网站把登录和首页放在一起设计,由此可见登录页面的重要性,一个出彩的登录界面,将提升产品的品质,赋予产品独特的气质,登录界面也是一个发挥情

JSP 用户登录处理界面显示空白怎么解决

问题描述 JSP 用户登录处理界面显示空白怎么解决 <%@ page language=""java"" contentType=""text/html; charset=GBK""%><%@ page import=""java.sql.*""%><html> <head> <title>业务处理页面</title>

java struts2-怎样利用Java 中的struts2框架实现数据库中用户登录功能?

问题描述 怎样利用Java 中的struts2框架实现数据库中用户登录功能? 在Action中LoginAction怎样写? 配置文件中怎样写? 总体实现能够使数据库中已经存在的用户凭自己的密码与用户名登录成功呢?数据库是Oracle数据库.

ASP用户登录模块的设计

ASP用户登录模块的设计 用户登录验证脚本,Chkpwd.asp <% '=======用户登录验证脚本======= '如果尚未定义Passed对象,则将其定义为false,表示没有通过验证 If IsEmpty(Session("Passed")) Then Session("Passed")=false End If   'Session("Passed")=False,表示尚未通过验证,则开始读取从表单传来的验证信息 If Sess

Dreamweaver构建Blog全程实录(7)-用户登录的实现

dreamweaver 第七章  Doking's BLOG用户登录页面的实现 已完成用户的注册,用户现在可以登录到网站中,发表笔记.笔记回复. 7.1  用户登录服务器行为 用户登录,经过验证正确,页面换了个用户登录后的面貌. (1)打开模板bkblog.dwt.aspx,在左边栏插入表格yhtab,并设计如图7-1黑色圈中所示. (2)插入关于YH表查询的数据集yhlog,以验证用户登录的正确. ①将数据集yhlog设为筛选,如图7-2所示. 图7-1  表格yhtab的设计图    开发全