[原创]实现基于数据库的程序验证

    Private Sub Page_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load
        
If Page.IsPostBack Then
            
Try
                
If TextBox2.Text = checkuser("user_pwd"Then
                    FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, 
True)
                
End If
            
Catch ex As Exception
                Response.
Write("验证失败,Please Check")
            
End Try
        
End If
    
End Sub


    
Public Function checkuser() As SqlDataReader
        
Dim conn As New SqlConnection("data source=localhost;initial catalog=db_xiannet;user id=sa;pwd=SC")
        
Dim com As New SqlCommand("select * from tb_xiannet_user where user_name='" & TextBox1.Text & "' and user_pwd='" & TextBox2.Text & "'", conn)
        
Dim reader As SqlDataReader
        conn.Open()
        
Try
            reader 
= com.ExecuteReader
            reader.Read()
        
Catch ex As Exception
        
End Try
        
Return reader
    
End Function

        此为数据库中的密码是经过MD5加密的

    Private Sub Page_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load
        
If Page.IsPostBack Then
            
Try
                
If FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox2.Text, "md5"= checkuser("user_pwd"Then
                    FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, 
True)
                
End If
            
Catch ex As Exception
                Response.
Write("验证失败,Please Check")
            
End Try
        
End If
    
End Sub


    
Public Function checkuser() As SqlDataReader
        
Dim conn As New SqlConnection("data source=localhost;initial catalog=db_xiannet;user id=sa;pwd=SC")
        
Dim com As New SqlCommand("select * from tb_xiannet_user where user_name='" & TextBox1.Text & "' and user_pwd='" & FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox2.Text, "md5"& "'", conn)
        
Dim reader As SqlDataReader
        conn.Open()
        
Try
            reader 
= com.ExecuteReader
            reader.Read()
        
Catch ex As Exception
        
End Try
        
Return reader
    
End Function
posted on 2005-03-07 18:06  雪无止境  阅读(259)  评论(0编辑  收藏  举报